-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil_test.go
93 lines (84 loc) · 2.96 KB
/
util_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package insteon
import (
"testing"
"time"
)
/*func TestChecksum(t *testing.T) {
tests := []struct {
desc string
input []byte
expected byte
}{
{"1", []byte{0x2E, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xd1},
{"2", []byte{0x2F, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xC2},
{"3", []byte{0x2F, 0x00, 0x01, 0x01, 0x0F, 0xFF, 0x00, 0xA2, 0x00, 0x19, 0x70, 0x1A, 0xFF, 0x1F, 0x01}, 0x5D},
{"4", []byte{0x2F, 0x00, 0x00, 0x00, 0x0F, 0xF7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xCA},
{"5", []byte{0x2F, 0x00, 0x01, 0x01, 0x0F, 0xF7, 0x00, 0xE2, 0x01, 0x19, 0x70, 0x1A, 0xFF, 0x1F, 0x01}, 0x24},
{"6", []byte{0x2F, 0x00, 0x00, 0x00, 0x0F, 0xEF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xD2},
{"7", []byte{0x2F, 0x00, 0x01, 0x01, 0x0F, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xD1},
{"8", []byte{0x2F, 0x00, 0x01, 0x02, 0x0F, 0xFF, 0x08, 0xE2, 0x01, 0x08, 0xB6, 0xEA, 0x00, 0x1B, 0x01}, 0x11},
{"9", []byte{0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0xF6},
{"A", []byte{0x2f, 0x00, 0x00, 0x02, 0x0f, 0xff, 0x08, 0xe2, 0x01, 0x08, 0xb6, 0xea, 0x00, 0x1b, 0x01}, 0x12},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
cmd := commands.Command(int(test.input[0])<<8 | int(test.input[1]))
got := byte(cmd.Command1()) + byte(cmd.Command2())
want := test.input[0] + test.input[1]
if want != got {
t.Errorf("Wanted byte 0x%02x got 0x%02x", want, got)
}
got = checksum(cmd, test.input[2:])
if got != test.expected {
t.Errorf("got checksum %02x, want %02x", got, test.expected)
}
})
}
}*/
func TestPropagationDelay(t *testing.T) {
tests := []struct {
name string
inputTTL uint8
inputLen int
want time.Duration
}{
{"ttl 0, standard", 0, 10, time.Second * 10 / 60},
{"ttl 0, extended", 0, 24, time.Second * 24 / 60},
{"ttl 2, standard", 2, 10, time.Second * 30 / 60},
{"ttl 2, extended", 2, 24, time.Second * 72 / 60},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := PropagationDelay(test.inputTTL, test.inputLen)
if test.want != got {
t.Errorf("Wanted delay %v got %v", test.want, got)
}
})
}
}
func TestReadWithTimeout(t *testing.T) {
fillChan := func(messages ...*Message) <-chan *Message {
ch := make(chan *Message, len(messages))
for _, msg := range messages {
ch <- msg
}
return ch
}
tests := []struct {
name string
inputCh <-chan *Message
inputTimeout time.Duration
want error
}{
{"success", fillChan(&Message{}), time.Second, nil},
{"success", fillChan(), time.Microsecond, ErrReadTimeout},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, got := ReadWithTimeout(test.inputCh, test.inputTimeout)
if test.want != got {
t.Errorf("Wanted error %v got %v", test.want, got)
}
})
}
}