update test for respond func

This commit is contained in:
Danny van Kooten 2018-09-21 10:50:34 +02:00
parent 734d32082a
commit 5507fbcd92

View File

@ -2,17 +2,22 @@ package api
import ( import (
"encoding/json" "encoding/json"
"net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
) )
func TestRespond(t *testing.T) { func TestRespond(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
respond(w, 15) respond(w, http.StatusOK, 15)
if w.Code != 200 {
t.Errorf("Invalid response code")
}
// assert json header // assert json header
if w.Header().Get("Content-Type") != "application/json" { if w.Header().Get("Content-Type") != "application/json" {
t.Errorf("Invalid Content-Type header") t.Errorf("Invalid response header for Content-Type")
} }
// assert json response // assert json response