-
Notifications
You must be signed in to change notification settings - Fork 1
/
daemon_test.go
38 lines (32 loc) · 1002 Bytes
/
daemon_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
package vproxy
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestListClients(t *testing.T) {
request, _ := http.NewRequest("GET", "/events/next/", nil)
response := httptest.NewRecorder()
vhostMux := CreateVhostMux([]string{}, true)
lh := NewLoggedHandler(vhostMux)
// start daemon
d := NewDaemon(lh, "127.0.0.1", 80, 443)
d.listClients(response, request)
if response.Code != http.StatusOK {
t.Fatalf("Non-expected status code%v:\n\tbody: %v", "200", response.Code)
}
response = httptest.NewRecorder()
d.addVhost("test.local.com:8888", httptest.NewRecorder())
d.listClients(response, request)
if response.Code != http.StatusOK {
t.Fatalf("Non-expected status code%v:\n\tbody: %v", "200", response.Code)
}
res := response.Body.String()
if len(strings.Split(res, "\n")) < 3 {
t.Fatalf("response too short:\n%s", res)
}
if !strings.Contains(res, "test.local.com") {
t.Fatalf("list does not contain test.local.com:\n%s", response.Body.String())
}
}