forked from tanema/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolt_test.go
72 lines (65 loc) · 1.31 KB
/
bolt_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
package bolt
import (
"encoding/binary"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
)
type (
user struct {
ID string
Name string
}
)
var u = user{
ID: "1",
Name: "Joe",
}
func TestMaxParam(t *testing.T) {
b := New(MaxParam(8))
if b.maxParam != 8 {
t.Errorf("max param should be 8, found %d", b.maxParam)
}
}
func TestIndex(t *testing.T) {
b := New()
b.Index("example/public/index.html")
r, _ := http.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
b.ServeHTTP(w, r)
if w.Code != 200 {
t.Errorf("status code should be 200, found %d", w.Code)
}
}
func TestStatic(t *testing.T) {
b := New()
b.Static("/js", "example/public/js")
r, _ := http.NewRequest("GET", "/js/main.js", nil)
w := httptest.NewRecorder()
b.ServeHTTP(w, r)
if w.Code != 200 {
t.Errorf("status code should be 200, found %d", w.Code)
}
}
func verifyUser(rd io.Reader, t *testing.T) {
var l int64
err := binary.Read(rd, binary.BigEndian, &l) // Body length
if err != nil {
t.Fatal(err)
}
bd := io.LimitReader(rd, l) // Body
u2 := new(user)
dec := json.NewDecoder(bd)
err = dec.Decode(u2)
if err != nil {
t.Fatal(err)
}
if u2.ID != u.ID {
t.Errorf("user id should be %s, found %s", u.ID, u2.ID)
}
if u2.Name != u.Name {
t.Errorf("user name should be %s, found %s", u.Name, u2.Name)
}
}