-
Notifications
You must be signed in to change notification settings - Fork 0
/
replyer_test.go
54 lines (50 loc) · 1.21 KB
/
replyer_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
package minigrush
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/crbrox/store/dummy"
)
func TestOk(t *testing.T) {
const data = `
{ a: 2, b: "b",
guay : true,
DOLLARS: 1234.5678
}`
const id = "1234_abc"
replyer := &Replyer{
ReplyStore: dummy.Store{},
}
replyer.ReplyStore.Put(id, []byte(data))
request, err := http.NewRequest("GET", "/one/two/three/"+id, nil)
if err != nil {
t.Error(err)
}
response := httptest.NewRecorder()
replyer.ServeHTTP(response, request)
if response.Code != 200 {
t.Error("response should be 200 for existent reply")
}
if response.Header().Get("Content-Type") != "application/json" {
t.Error("content type of response should be application/json")
}
if !reflect.DeepEqual(response.Body.Bytes(), []byte(data)) {
t.Error("response body should be equal to body reply")
}
}
func TestNotFound(t *testing.T) {
const id = "1234_abc"
replyer := &Replyer{
ReplyStore: dummy.Store{},
}
request, err := http.NewRequest("GET", "/one/two/three/"+id, nil)
if err != nil {
t.Error(err)
}
response := httptest.NewRecorder()
replyer.ServeHTTP(response, request)
if response.Code != 404 {
t.Error("response should be 404 for inexistent reply")
}
}