fathom/pkg/api/http_test.go

31 lines
528 B
Go
Raw Normal View History

2018-05-08 07:11:32 +00:00
package api
import (
"encoding/json"
2018-09-21 08:50:34 +00:00
"net/http"
2018-05-08 07:11:32 +00:00
"net/http/httptest"
"testing"
)
func TestRespond(t *testing.T) {
w := httptest.NewRecorder()
2018-09-21 08:50:34 +00:00
respond(w, http.StatusOK, 15)
if w.Code != 200 {
t.Errorf("Invalid response code")
}
2018-05-08 07:11:32 +00:00
// assert json header
if w.Header().Get("Content-Type") != "application/json" {
2018-09-21 08:50:34 +00:00
t.Errorf("Invalid response header for Content-Type")
2018-05-08 07:11:32 +00:00
}
// assert json response
var d int
err := json.NewDecoder(w.Body).Decode(&d)
if err != nil {
t.Errorf("Invalid response body: %s", err)
}
}