This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_test.go
66 lines (58 loc) · 1.5 KB
/
input_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
package lgtv
import (
"strings"
"testing"
"github.com/gorilla/websocket"
)
func TestGetInputs(t *testing.T) {
server, url := startClientServer(t, func(c *websocket.Conn, req string) {
if strings.Contains(req, "register") {
c.WriteMessage(websocket.TextMessage, []byte("{\"id\":1,\"type\":\"registered\",\"payload\":{\"client-key\":\"123\"}}"))
}
if strings.Contains(req, uriInputList) {
c.WriteMessage(websocket.TextMessage, []byte("{\"id\":2,\"type\":\"response\",\"payload\":{\"devices\":[{\"id\":\"foo\"},{\"id\":\"bar\"}]}}"))
}
})
defer server.Close()
lgtv := NewDefaultClient(url, key)
err := lgtv.Connect()
if err != nil {
t.Error(err)
}
defer lgtv.Disconnect()
list, err := lgtv.GetInputs()
if err != nil {
t.Error(err)
}
if len(list) != 2 {
t.Fail()
return
}
if list[0].ID != "foo" {
t.Fail()
}
if list[1].ID != "bar" {
t.Fail()
}
}
func TestSwitchInput(t *testing.T) {
server, url := startClientServer(t, func(c *websocket.Conn, req string) {
if strings.Contains(req, "register") {
c.WriteMessage(websocket.TextMessage, []byte("{\"id\":1,\"type\":\"registered\",\"payload\":{\"client-key\":\"123\"}}"))
}
if strings.Contains(req, uriInputSet) {
c.WriteMessage(websocket.TextMessage, []byte("{\"id\":2,\"type\":\"response\",\"payload\":null}"))
}
})
defer server.Close()
lgtv := NewDefaultClient(url, key)
err := lgtv.Connect()
if err != nil {
t.Error(err)
}
defer lgtv.Disconnect()
err = lgtv.SwitchInput("foo")
if err != nil {
t.Error(err)
}
}