-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlichtcgi_test.go
62 lines (50 loc) · 1.13 KB
/
lichtcgi_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
package main
import (
"testing"
)
func TestFetchLights(t *testing.T) {
t.Log("Fetching lights")
cgi := NewLichtCgi("http://localhost:2299")
lights, err := cgi.FetchLights(5)
if err != nil {
t.Log("licht.cgi stub server running?")
t.Error(err)
}
if len(lights) != 4 {
t.Error("Expected 4 values")
}
t.Log("Success. Retrieved:", lights)
}
func TestSetLight(t *testing.T) {
cgi := NewLichtCgi("http://localhost:2299")
err := cgi.Update(2, 127)
if err != nil {
t.Log("licht.cgi stub server running?")
t.Error(err)
}
// Read, check update
lights, err := cgi.FetchLights(5)
if err != nil {
t.Log("licht.cgi stub server running?")
t.Error(err)
}
if lights[2].Value != 127 {
t.Error("Expected light 2 to be set to 127")
}
t.Log("Success. Retrieved:", lights)
err = cgi.Update(2, 23)
if err != nil {
t.Log("licht.cgi stub server running?")
t.Error(err)
}
// Read, check update
lights, err = cgi.FetchLights(5)
if err != nil {
t.Log("licht.cgi stub server running?")
t.Error(err)
}
if lights[2].Value != 23 {
t.Error("Expected light 2 to be set to 23")
}
t.Log("Success. Retrieved:", lights)
}