-
Notifications
You must be signed in to change notification settings - Fork 2
/
device_removal_test.go
50 lines (39 loc) · 1.47 KB
/
device_removal_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
package zda
import (
"context"
"github.com/shimmeringbee/da/capabilities"
lw "github.com/shimmeringbee/logwrap"
"github.com/shimmeringbee/logwrap/impl/discard"
"github.com/shimmeringbee/zigbee"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)
func TestZigbeeDeviceRemoval_Remove(t *testing.T) {
t.Run("successfully calls RequestNodeLeave on provider with devices ieee and Request flag", func(t *testing.T) {
mockProvider := zigbee.MockProvider{}
defer mockProvider.AssertExpectations(t)
expectedIEEE := zigbee.GenerateLocalAdministeredIEEEAddress()
zed := deviceRemoval{
nodeRemover: &mockProvider,
logger: lw.New(discard.Discard()),
node: &node{address: expectedIEEE},
}
mockProvider.On("RequestNodeLeave", mock.Anything, expectedIEEE).Return(nil)
err := zed.Remove(context.Background(), capabilities.Request)
assert.NoError(t, err)
})
t.Run("successfully calls ForceNodeLeave on provider with devices ieee and Force flag", func(t *testing.T) {
mockProvider := zigbee.MockProvider{}
defer mockProvider.AssertExpectations(t)
expectedIEEE := zigbee.GenerateLocalAdministeredIEEEAddress()
zed := deviceRemoval{
nodeRemover: &mockProvider,
logger: lw.New(discard.Discard()),
node: &node{address: expectedIEEE},
}
mockProvider.On("ForceNodeLeave", mock.Anything, expectedIEEE).Return(nil)
err := zed.Remove(context.Background(), capabilities.Force)
assert.NoError(t, err)
})
}