-
Notifications
You must be signed in to change notification settings - Fork 5
/
inherent_test.go
75 lines (71 loc) · 1.71 KB
/
inherent_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2017-2024 The ivi developers. All rights reserved.
// Project site: https://github.com/gotmc/ivi
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE.txt file for the project.
package ivi
import (
"errors"
"testing"
)
func TestParseIdentification(t *testing.T) {
testCases := map[string]struct {
given string
part idPart
expected string
}{
"model": {
"HEWLETT-PACKARD,E3631A,0,1.4-5.0-1.0",
modelID,
"E3631A",
},
"firmware": {
"HEWLETT-PACKARD,E3631A,0,1.4-5.0-1.0",
fwrID,
"1.4-5.0-1.0",
},
"manufacturer": {
"HEWLETT-PACKARD,E3631A,0,1.4-5.0-1.0",
mfrID,
"HEWLETT-PACKARD",
},
"serial_number": {
"HEWLETT-PACKARD,E3631A,0,1.4-5.0-1.0",
snID,
"0",
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
got, err := parseIdentification(testCase.given, testCase.part)
if err != nil {
t.Errorf("got error %s / expected nil", err)
}
if got != testCase.expected {
t.Errorf("got %s / expected %s", got, testCase.expected)
}
})
}
}
func TestParseIdentificationErrors(t *testing.T) {
testCases := map[string]struct {
given string
expectedError error
}{
"empty_idn": {
"",
errors.New("idn string (``) could not be split in four"),
},
"partial_idn": {
"HEWLETT-PACKARD,E3631A",
errors.New("idn string (``) could not be split in four"),
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
_, err := parseIdentification(testCase.given, fwrID)
if errors.Is(err, testCase.expectedError) && testCase.expectedError != nil {
t.Errorf("got error %s / expected %s", err, testCase.expectedError)
}
})
}
}