-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinherent_test.go
More file actions
76 lines (72 loc) · 1.73 KB
/
inherent_test.go
File metadata and controls
76 lines (72 loc) · 1.73 KB
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
76
// Copyright (c) 2017-2026 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 (
"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
expectedMsg string
}{
"empty_idn": {
"",
"idn string (``) could not be split in four",
},
"partial_idn": {
"HEWLETT-PACKARD,E3631A",
"idn string (`HEWLETT-PACKARD,E3631A`) could not be split in four",
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
_, err := parseIdentification(testCase.given, fwrID)
if err == nil {
t.Errorf("expected error, got nil")
} else if err.Error() != testCase.expectedMsg {
t.Errorf("got error %q / expected %q", err.Error(), testCase.expectedMsg)
}
})
}
}