You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
652 B
30 lines
652 B
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHealthReturnsOK(t *testing.T) {
|
|
router := NewRouter(nil, nil, nil)
|
|
|
|
request := httptest.NewRequest(http.MethodGet, "/health", nil)
|
|
response := httptest.NewRecorder()
|
|
|
|
router.ServeHTTP(response, request)
|
|
|
|
if response.Code != http.StatusOK {
|
|
t.Fatalf("expected status %d, got %d", http.StatusOK, response.Code)
|
|
}
|
|
|
|
var body map[string]string
|
|
if err := json.NewDecoder(response.Body).Decode(&body); err != nil {
|
|
t.Fatalf("decode response body: %v", err)
|
|
}
|
|
|
|
if body["status"] != "ok" {
|
|
t.Fatalf("expected status ok, got %q", body["status"])
|
|
}
|
|
}
|
|
|