forked from pottava/docker-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
52 lines (45 loc) · 1.2 KB
/
main_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
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/pottava/docker-webui/app/config"
"github.com/pottava/docker-webui/app/misc"
)
func TestIndex(t *testing.T) {
cfg := config.NewConfig()
ts := httptest.NewServer(http.Handler(index(cfg)))
defer ts.Close()
res, err := http.Get(ts.URL)
if ok := misc.IsSuccessHTTPRequest(t, res, err); !ok {
return
}
actual, _ := misc.ParseHTTPResponse(res)
expected := config.NewConfig().Name
if !strings.Contains(actual, expected) {
t.Errorf("Invalid response. Expected %v, but got %v", expected, actual)
return
}
}
func TestAlive(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(alive))
defer ts.Close()
res, err := http.Get(ts.URL)
misc.IsSuccessHTTPRequest(t, res, err)
}
func TestAssets(t *testing.T) {
cfg := config.NewConfig()
ts := httptest.NewServer(http.Handler(assets(cfg)))
defer ts.Close()
res, err := http.Get(ts.URL + "/assets/css/main.css")
if ok := misc.IsSuccessHTTPRequest(t, res, err); !ok {
return
}
actual, _ := misc.ParseHTTPResponse(res)
expected := "monospace"
if !strings.Contains(actual, expected) {
t.Errorf("Invalid response. Expected %v, but got %v", expected, actual)
return
}
}