-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpersistence_test.go
83 lines (60 loc) · 2.37 KB
/
persistence_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
package zda
import (
"context"
"github.com/shimmeringbee/persistence/impl/memory"
"github.com/shimmeringbee/zigbee"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_gateway_deviceListFromPersistence(t *testing.T) {
t.Run("multiple devices are returned", func(t *testing.T) {
zgw := New(context.Background(), memory.New(), nil, nil)
ieee := zigbee.GenerateLocalAdministeredIEEEAddress()
deviceOne := IEEEAddressWithSubIdentifier{IEEEAddress: ieee, SubIdentifier: 1}
deviceTwo := IEEEAddressWithSubIdentifier{IEEEAddress: ieee, SubIdentifier: 2}
zgw.sectionForDevice(deviceOne)
zgw.sectionForDevice(deviceTwo)
devices := zgw.deviceListFromPersistence(ieee)
assert.Contains(t, devices, deviceOne)
assert.Contains(t, devices, deviceTwo)
})
}
func Test_gateway_nodeListFromPersistence(t *testing.T) {
t.Run("multiple nodes are returned", func(t *testing.T) {
zgw := New(context.Background(), memory.New(), nil, nil)
ieeeOne := zigbee.GenerateLocalAdministeredIEEEAddress()
ieeeTwo := zigbee.GenerateLocalAdministeredIEEEAddress()
zgw.sectionForNode(ieeeOne)
zgw.sectionForNode(ieeeTwo)
nodes := zgw.nodeListFromPersistence()
assert.Contains(t, nodes, ieeeOne)
assert.Contains(t, nodes, ieeeTwo)
})
}
func Test_gateway_sectionRemoveNode(t *testing.T) {
t.Run("nodes are removed", func(t *testing.T) {
zgw := New(context.Background(), memory.New(), nil, nil)
ieeeOne := zigbee.GenerateLocalAdministeredIEEEAddress()
ieeeTwo := zigbee.GenerateLocalAdministeredIEEEAddress()
zgw.sectionForNode(ieeeOne)
zgw.sectionForNode(ieeeTwo)
assert.True(t, zgw.sectionRemoveNode(ieeeTwo))
nodes := zgw.nodeListFromPersistence()
assert.Contains(t, nodes, ieeeOne)
assert.NotContains(t, nodes, ieeeTwo)
})
}
func Test_gateway_sectionRemoveDevice(t *testing.T) {
t.Run("devices is removed", func(t *testing.T) {
zgw := New(context.Background(), memory.New(), nil, nil)
ieee := zigbee.GenerateLocalAdministeredIEEEAddress()
deviceOne := IEEEAddressWithSubIdentifier{IEEEAddress: ieee, SubIdentifier: 1}
deviceTwo := IEEEAddressWithSubIdentifier{IEEEAddress: ieee, SubIdentifier: 2}
zgw.sectionForDevice(deviceOne)
zgw.sectionForDevice(deviceTwo)
assert.True(t, zgw.sectionRemoveDevice(deviceTwo))
devices := zgw.deviceListFromPersistence(ieee)
assert.Contains(t, devices, deviceOne)
assert.NotContains(t, devices, deviceTwo)
})
}