-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathdevice_test.go
117 lines (99 loc) · 2.44 KB
/
device_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build integration
// +build integration
package linking
import (
"testing"
)
func TestAddDevice(t *testing.T) {
if skipTest() {
t.SkipNow()
}
c := getTestManager()
// delete if exist
device := "sdk-testAddDevice"
defer c.DeleteDevice(testApp, device)
dev := &Device{
Device: device,
SegmentExpireDays: 7,
}
_, err := c.AddDevice(testApp, dev)
noError(t, err)
}
func TestQueryDevice(t *testing.T) {
if skipTest() {
t.SkipNow()
}
c := getTestManager()
device := "sdk-testQueryDevice"
defer c.DeleteDevice(testApp, device)
dev := &Device{
Device: device,
SegmentExpireDays: 7,
}
_, err := c.AddDevice(testApp, dev)
noError(t, err)
dev2, err := c.QueryDevice(testApp, device)
noError(t, err)
shouldBeEqual(t, 7, dev2.SegmentExpireDays)
}
func TestUpdateDevice(t *testing.T) {
if skipTest() {
t.SkipNow()
}
c := getTestManager()
device := "sdk-testUpdateDevice"
defer c.DeleteDevice(testApp, device)
dev := &Device{
Device: device,
SegmentExpireDays: 7,
}
_, err := c.AddDevice(testApp, dev)
noError(t, err)
dev2, err := c.QueryDevice(testApp, device)
noError(t, err)
shouldBeEqual(t, 7, dev2.SegmentExpireDays)
// udpate device segmentexpiredays to 30
ops := []PatchOperation{
{Op: "replace", Key: "segmentExpireDays", Value: 30},
}
dev3, err := c.UpdateDevice(testApp, device, ops)
noError(t, err)
shouldBeEqual(t, 30, dev3.SegmentExpireDays)
}
func TestListDevice(t *testing.T) {
if skipTest() {
t.SkipNow()
}
c := getTestManager()
device1 := "sdk-testListDevice1"
defer c.DeleteDevice(testApp, device1)
dev1 := &Device{
Device: device1,
SegmentExpireDays: 7,
}
_, err := c.AddDevice(testApp, dev1)
noError(t, err)
device2 := "sdk-testListDevice2"
defer c.DeleteDevice(testApp, device2)
dev2 := &Device{
Device: device2,
SegmentExpireDays: 7,
}
_, err = c.AddDevice(testApp, dev2)
noError(t, err)
device3 := "sdk-testListDevice3"
defer c.DeleteDevice(testApp, device3)
dev3 := &Device{
Device: device3,
SegmentExpireDays: 7,
}
_, err = c.AddDevice(testApp, dev3)
noError(t, err)
devices, marker, err := c.ListDevice(testApp, "sdk-testListDevice", "", 2, false, false, 0, "")
noError(t, err)
shouldBeEqual(t, 2, len(devices))
devices, marker, err = c.ListDevice(testApp, "sdk-testListDevice", "", 1000, false, false, 0, "")
noError(t, err)
shouldBeEqual(t, 3, len(devices))
shouldBeEqual(t, "", marker)
}