-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservice_test.go
84 lines (78 loc) · 2.16 KB
/
service_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package structexplorer
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestServe(t *testing.T) {
var some = struct {
s string
i int
t time.Time
}{
s: "s",
i: 1,
t: time.Now(),
}
h := NewService("test", some).(*service)
// GET
rec := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
h.ServeHTTP(rec, req)
if got, want := rec.Code, 200; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
if got, want := rec.Header().Get("content-type"), "text/html"; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
// POST
action := `{"row":0,"column":0,"action":"down","selections":["t"]}`
rec = httptest.NewRecorder()
req, _ = http.NewRequest("POST", "/", strings.NewReader(action))
h.ServeHTTP(rec, req)
if got, want := rec.Code, 200; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
if got, want := len(h.explorer.accessMap[1]), 1; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
}
func TestServiceFollow(t *testing.T) {
s := NewService("now", time.Now()).(*service)
s.ExplorePath("now.loc")
oa := s.explorer.accessMap[0][1]
if got, want := oa.label, "now.loc"; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
s.ExplorePath("now.ext", RowColumn(1, 1))
oa = s.explorer.accessMap[1][1]
if got, want := oa.label, "now.ext"; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
}
func TestServiceExplore(t *testing.T) {
s := NewService().(*service)
s.Explore("now", time.Now())
oa := s.explorer.accessMap[0][0]
if got, want := oa.label, "now"; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
s.Dump()
}
func TestServiceExploreWithOption(t *testing.T) {
s := NewService().(*service)
s.Explore("now", time.Now(), RowColumn(2, 2))
oa := s.explorer.accessMap[2][2]
if got, want := oa.label, "now"; got != want {
t.Errorf("got [%[1]v:%[1]T] want [%[2]v:%[2]T]", got, want)
}
}
func TestServicEmptyFollow(t *testing.T) {
s := NewService().(*service)
s.ExplorePath("")
if len(s.explorer.accessMap) != 0 {
t.Fail()
}
}