Skip to content

Commit

Permalink
expand test
Browse files Browse the repository at this point in the history
  • Loading branch information
dekokun committed Feb 5, 2018
1 parent 1ec6343 commit 9a7c44d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -69,3 +70,39 @@ func TestHandleBody(t *testing.T) {
t.Errorf("got %v\nwant %v", actual, expected)
}
}

func TestHandleBodyInvalidJson(t *testing.T) {
reqBody := `
Hogefuga
`

_, err := handleRequestBody(reqBody)
if err == nil {
t.Errorf("not got err %v\n", err)
}
}

func TestMakeResponse(t *testing.T) {

body := "body"
actual := makeResponse(body, nil)
expected := 200
if actual.StatusCode != expected {
t.Errorf("got %v\nwant %v", actual.StatusCode, expected)
}
expectedBody := body
if actual.Body != expectedBody {
t.Errorf("got %v\nwant %v", actual.Body, expectedBody)
}
}

func TestMakeResponseErr(t *testing.T) {

body := "body"
err := errors.New("error")
actual := makeResponse(body, err)
expected := 504
if actual.StatusCode != expected {
t.Errorf("got %v\nwant %v", actual.StatusCode, expected)
}
}

0 comments on commit 9a7c44d

Please sign in to comment.