-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces_test.go
76 lines (61 loc) · 1.82 KB
/
interfaces_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
package deferr_test
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/marconi/deferr"
)
type FakeTodoManager struct{}
func (ftm *FakeTodoManager) List() []*deferr.Todo {
return []*deferr.Todo{
&deferr.Todo{
Slug: "todo-123",
Name: "Wash clothes",
},
}
}
func (ftm *FakeTodoManager) Push(t *deferr.Todo) error {
t.Slug = "todo-123"
return nil
}
func (ftm *FakeTodoManager) Pop() (*deferr.Todo, error) {
return nil, nil
}
func (ftm *FakeTodoManager) Defer() error {
return nil
}
func TestWebHandlerSpec(t *testing.T) {
handler := deferr.NewWebHandler(&FakeTodoManager{})
Convey("testing web handler", t, func() {
Convey("should be able to push item", func() {
body := bytes.NewBufferString("")
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/todos", body)
handler.Push(w, req, nil)
So(w.Body.String(), ShouldEqual, `{"message":"Invalid payload."}`)
body = bytes.NewBufferString(`{"name":"Wash clothes"}`)
w = httptest.NewRecorder()
req, _ = http.NewRequest("POST", "/todos", body)
handler.Push(w, req, nil)
So(w.Body.String(), ShouldEqual, `{"slug":"todo-123","name":"Wash clothes"}`)
})
Convey("should be able to list items", func() {
body := bytes.NewBufferString(`{"name":"Wash clothes"}`)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/todos", body)
handler.Push(w, req, nil)
w = httptest.NewRecorder()
req, _ = http.NewRequest("GET", "/todos", nil)
handler.List(w, req, nil)
So(w.Body.String(), ShouldEqual, `[{"slug":"todo-123","name":"Wash clothes"}]`)
})
Convey("should be able to pop item", func() {
// TODO: exercise, implement this yourself
})
Convey("should be able to defer item", func() {
// TODO: exercise, implement this yourself
})
})
}