-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathconfig_test.go
168 lines (154 loc) · 4.83 KB
/
config_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package huego
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetConfig(t *testing.T) {
b := New(hostname, username)
config, err := b.GetConfig()
if err != nil {
t.Fatal(err)
}
t.Logf("Name: %s", config.Name)
t.Logf("SwUpdate:")
t.Logf(" CheckForUpdate: %t", config.SwUpdate.CheckForUpdate)
t.Logf(" DeviceTypes:")
t.Logf(" Bridge: %t", config.SwUpdate.DeviceTypes.Bridge)
t.Logf(" Lights (length): %d", len(config.SwUpdate.DeviceTypes.Lights))
t.Logf(" Sensors (length): %d", len(config.SwUpdate.DeviceTypes.Sensors))
t.Logf(" UpdateState: %d", config.SwUpdate.UpdateState)
t.Logf(" Notify: %t", config.SwUpdate.Notify)
t.Logf(" URL: %s", config.SwUpdate.URL)
t.Logf(" Text: %s", config.SwUpdate.Text)
t.Logf("SwUpdate2:")
t.Logf(" Bridge: %s", config.SwUpdate2.Bridge)
t.Logf(" State: %s", config.SwUpdate2.Bridge.State)
t.Logf(" LastInstall: %s", config.SwUpdate2.Bridge.LastInstall)
t.Logf(" CheckForUpdate: %t", config.SwUpdate2.CheckForUpdate)
t.Logf(" State: %s", config.SwUpdate2.State)
t.Logf(" Install: %t", config.SwUpdate2.Install)
t.Logf(" AutoInstall:")
t.Logf(" On: %t", config.SwUpdate2.AutoInstall.On)
t.Logf(" UpdateTime: %s", config.SwUpdate2.AutoInstall.UpdateTime)
t.Logf(" LastChange: %s", config.SwUpdate2.LastChange)
t.Logf(" LastInstall: %s", config.SwUpdate2.LastInstall)
t.Logf("Whitelist (length): %d", len(config.Whitelist))
t.Logf("PortalState:")
t.Logf(" SignedOn: %t", config.PortalState.SignedOn)
t.Logf(" Incoming: %t", config.PortalState.Incoming)
t.Logf(" Outgoing: %t", config.PortalState.Outgoing)
t.Logf(" Communication: %s", config.PortalState.Communication)
t.Logf("APIVersion: %s", config.APIVersion)
t.Logf("SwVersion: %s", config.SwVersion)
t.Logf("ProxyAddress: %s", config.ProxyAddress)
t.Logf("ProxyPort: %d", config.ProxyPort)
t.Logf("LinkButton: %t", config.LinkButton)
t.Logf("IPAddress: %s", config.IPAddress)
t.Logf("Mac: %s", config.Mac)
t.Logf("NetMask: %s", config.NetMask)
t.Logf("Gateway: %s", config.Gateway)
t.Logf("Dhcp: %t", config.Dhcp)
t.Logf("PortalServices: %t", config.PortalServices)
t.Logf("UTC: %s", config.UTC)
t.Logf("LocalTime: %s", config.LocalTime)
t.Logf("TimeZone: %s", config.TimeZone)
t.Logf("ZigbeeChannel: %d", config.ZigbeeChannel)
t.Logf("ModelID: %s", config.ModelID)
t.Logf("BridgeID: %s", config.BridgeID)
t.Logf("FactoryNew: %t", config.FactoryNew)
t.Logf("ReplacesBridgeID: %s", config.ReplacesBridgeID)
t.Logf("DatastoreVersion: %s", config.DatastoreVersion)
t.Logf("StarterKitID: %s", config.StarterKitID)
}
func TestGetConfigError(t *testing.T) {
b := New(badHostname, username)
_, err := b.GetConfig()
if err == nil {
t.Fatal("Expected error not to be nil")
}
}
func TestCreateUser(t *testing.T) {
b := New(hostname, "")
u, err := b.CreateUser("github.com/amimof/huego#go test")
if err != nil {
t.Fatal(err)
} else {
t.Logf("User created with username: %s", u)
}
}
func TestCreateUserError(t *testing.T) {
b := New(badHostname, username)
_, err := b.CreateUser("github.com/amimof/huego#go test")
if err == nil {
t.Fatal("Expected error not to be nil")
}
}
func TestCreateUserWithClientKey(t *testing.T) {
b := New(hostname, "")
u, err := b.CreateUserWithClientKey("github.com/amimof/huego#go test")
if err != nil {
t.Fatal(err)
} else {
t.Logf("User created with username: %s", u)
}
}
func TestCreateUserWithClientKeyError(t *testing.T) {
b := New(badHostname, username)
_, err := b.CreateUserWithClientKey("github.com/amimof/huego#go test")
if err == nil {
t.Fatal("Expected error not to be nil")
}
}
func TestGetUsers(t *testing.T) {
b := New(hostname, username)
users, err := b.GetUsers()
if err != nil {
t.Fatal(err)
}
for i, u := range users {
t.Logf("%d:", i)
t.Logf(" Name: %s", u.Name)
t.Logf(" Username: %s", u.Username)
t.Logf(" CreateDate: %s", u.CreateDate)
t.Logf(" LastUseDate: %s", u.LastUseDate)
}
contains := func(name string, ss []Whitelist) bool {
for _, s := range ss {
if s.Name == name {
return true
}
}
return false
}
assert.True(t, contains("PhilipsHueAndroidApp#TCTALCATELONETOU", users))
assert.True(t, contains("MyApplication", users))
}
func TestGetUsersError(t *testing.T) {
b := New(badHostname, username)
_, err := b.GetUsers()
if err == nil {
t.Fatal("Expected error not to be nil")
}
}
func TestDeleteUser(t *testing.T) {
b := New(hostname, username)
err := b.DeleteUser("ffffffffe0341b1b376a2389376a2389")
if err != nil {
t.Fatal(err)
}
t.Logf("Deleted user '%s'", "ffffffffe0341b1b376a2389376a2389")
}
func TestGetFullState(t *testing.T) {
b := New(hostname, username)
_, err := b.GetFullState()
if err != nil {
t.Fatal(err)
}
}
func TestGetFullStateError(t *testing.T) {
b := New(badHostname, username)
_, err := b.GetFullState()
if err == nil {
t.Fatal("Expected error not to be nil")
}
}