-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
75 lines (70 loc) · 1.48 KB
/
main_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
package main
import (
"os"
"testing"
"github.com/go-kit/log"
"github.com/google/gousb"
)
func TestGenKey(t *testing.T) {
tests := []struct {
name string
desc gousb.DeviceDesc
want string
humanReadable bool
}{
{
name: "short label",
want: "nudl.squat.ai/8086_0044",
humanReadable: false,
desc: gousb.DeviceDesc{
Vendor: 0x8086,
Product: 0x0044,
},
},
{
name: "short label human readable",
want: "nudl.squat.ai/Intel-Corp._CPU-DRAM-Controller",
humanReadable: true,
desc: gousb.DeviceDesc{
Vendor: 0x8086,
Product: 0x0044,
},
},
{
name: "long label",
want: "nudl.squat.ai/8086_0200",
humanReadable: false,
desc: gousb.DeviceDesc{
Vendor: 0x8086,
Product: 0x0200,
},
},
{
name: "long label human readable fallback to hex",
want: "nudl.squat.ai/8086_0200",
humanReadable: true,
desc: gousb.DeviceDesc{
Vendor: 0x8086,
Product: 0x0200,
},
},
{
name: "device not found",
want: "nudl.squat.ai/0001_0001",
humanReadable: true,
desc: gousb.DeviceDesc{
Vendor: 0x0001,
Product: 0x0001,
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
humanReadable = &tc.humanReadable
got := genKey(&tc.desc, log.NewLogfmtLogger(os.Stdout))
if got != tc.want {
t.Errorf("genKey() = %q; want %q", got, tc.want)
}
})
}
}