-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebui_test.go
More file actions
83 lines (77 loc) · 2.13 KB
/
webui_test.go
File metadata and controls
83 lines (77 loc) · 2.13 KB
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
package main
import (
"testing"
"net/http/httptest"
"net/http"
"fmt"
)
func TestWebUI_MainPage(t *testing.T) {
ui := WebUI{}
url := "http://localhost"
req := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
ui.MainPage(w, req)
if w.Code != http.StatusOK {
t.Errorf("Wrong StatusCode: got %d, expected %d", w.Code, http.StatusOK)
}
}
func TestWebUI_LoadPreset(t *testing.T) {
ui := WebUI{}
ui.MsgChan = make(chan string)
url := "http://localhost/load?preset=0"
req := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
ui.LoadPreset(w, req)
if w.Code != http.StatusTemporaryRedirect {
t.Errorf("Wrong StatusCode: got %d, expected %d", w.Code, http.StatusTemporaryRedirect)
}
cmd := <-ui.MsgChan
if cmd != fmt.Sprintf(PresetCmd, "0") {
t.Errorf("Get wrong command: %s", cmd)
}
}
func TestWebUI_PlayButton(t *testing.T) {
ui := WebUI{}
ui.MsgChan = make(chan string)
url := "http://localhost/play"
req := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
ui.PlayButton(w, req)
if w.Code != http.StatusTemporaryRedirect {
t.Errorf("Wrong StatusCode: got %d, expected %d", w.Code, http.StatusTemporaryRedirect)
}
cmd := <-ui.MsgChan
if cmd != PlayCmd {
t.Errorf("Get wrong command: %s", cmd)
}
}
func TestWebUI_PauseButton(t *testing.T) {
ui := WebUI{}
ui.MsgChan = make(chan string)
url := "http://localhost/pause"
req := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
ui.PauseButton(w, req)
if w.Code != http.StatusTemporaryRedirect {
t.Errorf("Wrong StatusCode: got %d, expected %d", w.Code, http.StatusTemporaryRedirect)
}
cmd := <-ui.MsgChan
if cmd != PauseCmd {
t.Errorf("Get wrong command: %s", cmd)
}
}
func TestWebUI_StopButton(t *testing.T) {
ui := WebUI{}
ui.MsgChan = make(chan string)
url := "http://localhost/stop"
req := httptest.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
ui.StopButton(w, req)
if w.Code != http.StatusTemporaryRedirect {
t.Errorf("Wrong StatusCode: got %d, expected %d", w.Code, http.StatusTemporaryRedirect)
}
cmd := <-ui.MsgChan
if cmd != StopCmd {
t.Errorf("Get wrong command: %s", cmd)
}
}