-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbridge_test.go
51 lines (43 loc) · 994 Bytes
/
bridge_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
package hue
import (
"encoding/json"
"fmt"
"testing"
)
func TestGetNewLights(t *testing.T) {
bridge := NewBridge(host, username)
_, _, err := bridge.GetNewLights()
if err != nil {
t.Fail()
}
}
func TestSearchAndGetNewLights(t *testing.T) {
bridge := NewBridge(host, username)
_, err := bridge.Search()
if err != nil {
fmt.Printf("unable to search => %s\n", err)
t.Fail()
}
lights, lastScan, err := bridge.GetNewLights()
if err != nil {
fmt.Printf("GetNewLights => %s\n", err)
t.Fail()
}
fmt.Printf("lights => %+v\n", lights)
fmt.Printf("lastScan => %+v\n", lastScan)
}
func TestParseGetNewLights(t *testing.T) {
data := []byte(`{
"7": {"name": "Hue Lamp 7"},
"8": {"name": "Hue Lamp 8"},
"lastscan": "2012-10-29T12:00:00"
}`)
results := make(map[string]interface{})
err := json.Unmarshal(data, &results)
if err != nil {
fmt.Printf("%+v\n", err)
t.Fail()
}
value := results["7"].(map[string]interface{})
fmt.Printf("%#v\n", value["name"])
}