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