-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroups_test.go
98 lines (90 loc) · 1.87 KB
/
groups_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
package hue
import (
"fmt"
"os"
"testing"
"github.com/gosticks/go-hue-interface/utils"
)
func TestParseGroups(t *testing.T) {
v := make(map[string]*Group)
err := utils.CompareJSONDecode(groupsTestData, &v)
if err != nil {
t.Fail()
}
}
func TestBridgeGroupsParse(t *testing.T) {
userID, okUser := os.LookupEnv("HUE_BRIDGE_USER")
addr, okAddr := os.LookupEnv("HUE_BRIDGE_ADDR")
if !okAddr || !okUser {
fmt.Println("HUE_BRIDGE_USER and HUE_BRIDGE_ADDR must be set in env for this test to work")
t.Fail()
}
conf := &Config{
Username: userID,
BridgeAddr: addr,
BridgeAddrScheme: "http",
}
b := NewBridge(conf)
resp, respErr := b.getRawResponse(groupsEndpoint)
if respErr != nil {
t.Log(respErr)
t.Error()
}
groups, errGroups := b.GetAllGroups()
if errGroups != nil {
t.Log(errGroups)
t.Error()
}
errComp := utils.CompareStructToJSON(groups, string(resp))
if errComp != nil {
t.Fail()
}
}
const groupsTestData = `
{
"1": {
"name": "Group 1",
"lights": [
"1",
"2"
],
"type": "LightGroup",
"action": {
"on": true,
"bri": 254,
"hue": 10000,
"sat": 254,
"effect": "none",
"xy": [
0.5,
0.5
],
"ct": 250,
"alert": "select",
"colormode": "ct"
}
},
"2": {
"name": "Group 2",
"lights": [
"3",
"4",
"5"
],
"type": "LightGroup",
"action": {
"on": true,
"bri": 153,
"hue": 4345,
"sat": 254,
"effect": "none",
"xy": [
0.5,
0.5
],
"ct": 250,
"alert": "select",
"colormode": "ct"
}
}
}`