-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
58 lines (46 loc) · 1.32 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
package main
import (
"github.com/shimmeringbee/controller/state"
"github.com/shimmeringbee/da"
"github.com/shimmeringbee/da/mocks"
"github.com/shimmeringbee/persistence/impl/memory"
"github.com/shimmeringbee/zigbee"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func Test_updateDeviceOrganiserFromMux(t *testing.T) {
t.Run("adds a device when a DeviceAdded event is received", func(t *testing.T) {
do := state.NewDeviceOrganiser(memory.New(), state.NullEventPublisher)
addr := zigbee.GenerateLocalAdministeredIEEEAddress()
ch := updateDeviceOrganiserFromMux(&do)
defer func() {
ch <- nil
}()
ch <- da.DeviceAdded{
Device: mocks.SimpleDevice{
SIdentifier: addr,
},
}
time.Sleep(10 * time.Millisecond)
_, found := do.Device(addr.String())
assert.True(t, found)
})
t.Run("removes a device when a DeviceRemoved event is received", func(t *testing.T) {
do := state.NewDeviceOrganiser(memory.New(), state.NullEventPublisher)
addr := zigbee.GenerateLocalAdministeredIEEEAddress()
do.AddDevice(addr.String())
ch := updateDeviceOrganiserFromMux(&do)
defer func() {
ch <- nil
}()
ch <- da.DeviceRemoved{
Device: mocks.SimpleDevice{
SIdentifier: addr,
},
}
time.Sleep(10 * time.Millisecond)
_, found := do.Device(addr.String())
assert.False(t, found)
})
}