-
Notifications
You must be signed in to change notification settings - Fork 2
/
filter_test.go
59 lines (51 loc) · 1.45 KB
/
filter_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
package usbmon
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestActionFilter(t *testing.T) {
d := Device{
properties: map[string]string{"ACTION": "add"},
}
f := ActionFilter{Action: ActionAdd}
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "all"
assert.False(t, f.Matches(&d))
d.properties["ACTION"] = "remove"
assert.False(t, f.Matches(&d))
f = ActionFilter{Action: ActionAll}
d.properties["ACTION"] = "all"
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "add"
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "remove"
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "unbind"
assert.False(t, f.Matches(&d))
d.properties["ACTION"] = "bind"
assert.False(t, f.Matches(&d))
f = ActionFilter{Action: ActionRemove}
d.properties["ACTION"] = "all"
assert.False(t, f.Matches(&d))
d.properties["ACTION"] = "add"
assert.False(t, f.Matches(&d))
d.properties["ACTION"] = "remove"
assert.True(t, f.Matches(&d))
}
func TestSerialFilter(t *testing.T) {
d := Device{
properties: map[string]string{"ACTION": "add", "ID_SERIAL_SHORT": "1234"},
}
f := SerialFilter{Serial: "1234"}
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "bind"
assert.False(t, f.Matches(&d))
d.properties["ACTION"] = "remove"
assert.True(t, f.Matches(&d))
d.properties["ACTION"] = "unbind"
assert.False(t, f.Matches(&d))
f.Serial = ""
assert.False(t, f.Matches(&d))
f.Serial = "123"
assert.False(t, f.Matches(&d))
}