-
Notifications
You must be signed in to change notification settings - Fork 9
/
tibber_test.go
73 lines (66 loc) · 1.61 KB
/
tibber_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
package tibber
import (
"io/ioutil"
"path/filepath"
"testing"
"time"
)
func helperLoadBytes(t *testing.T, name string) []byte {
path := filepath.Join("testdata", name) // relative path
bytes, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return bytes
}
func TestGetHomes(t *testing.T) {
token := string(helperLoadBytes(t, "token.txt"))
tc := NewClient(token)
homes, _ := tc.GetHomes()
if homes == nil {
t.Fatalf("GetHomes: %v", homes)
}
}
func TestGetHomeById(t *testing.T) {
token := string(helperLoadBytes(t, "token.txt"))
tc := NewClient(token)
homeID := string(helperLoadBytes(t, "homeId.txt"))
home, _ := tc.GetHomeById(homeID)
if home.ID == "" {
t.Fatalf("GetHomeById: %s %v", homeID, home)
}
}
func TestPush(t *testing.T) {
token := string(helperLoadBytes(t, "token.txt"))
tc := NewClient(token)
_, err := tc.SendPushNotification("Golang Test", "Running golang test")
if err != nil {
t.Fatalf("Push: %v", err)
}
}
func TestStreams(t *testing.T) {
var msgCh MsgChan
token := string(helperLoadBytes(t, "token.txt"))
homeID := string(helperLoadBytes(t, "homeId.txt"))
stream := NewStream(homeID, token)
err := stream.StartSubscription(msgCh)
if err != nil {
t.Fatalf("Push: %v", err)
}
select {
case msg := <-msgCh:
t.Log(msg)
case <-time.After(time.Second * 7):
break
}
stream.Stop()
}
func TestGetCurrentPrice(t *testing.T) {
token := string(helperLoadBytes(t, "token.txt"))
tc := NewClient(token)
homeID := string(helperLoadBytes(t, "homeId.txt"))
priceInfo, _ := tc.GetCurrentPrice(homeID)
if priceInfo.Level == "" {
t.Fatalf("GetCurrentPrice: %v", priceInfo)
}
}