Skip to content

Commit 446a029

Browse files
committed
fixed handler test
1 parent 1c9c297 commit 446a029

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kadai4/main_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"io/ioutil"
56
"net/http"
67
"net/http/httptest"
@@ -24,8 +25,14 @@ func TestHandler(t *testing.T) {
2425
t.Fatal("unexpected error")
2526
}
2627

27-
const expected = `{"msg":"大吉"}`
28-
if s := string(b); s != expected {
29-
t.Fatalf("unexpected response: %s", s)
28+
res := &Response{}
29+
// TODO: 実行時のseeder設定により、大吉しか返ってないので、テストが通る
30+
const expected = "大吉"
31+
if err := json.Unmarshal(b, res); err != nil {
32+
t.Fatalf("JSON unmarshall error: %v", err)
33+
}
34+
35+
if res.Msg != string(expected) {
36+
t.Fatalf("unexpected response: %s", res.Msg)
3037
}
3138
}

0 commit comments

Comments
 (0)