Files
catalyst/app/service/http_test.go
2025-09-02 21:58:08 +02:00

30 lines
590 B
Go

package service
import (
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestJsonError(t *testing.T) {
t.Parallel()
rec := httptest.NewRecorder()
err := errors.New("test error")
r := httptest.NewRequest(http.MethodGet, "/", nil)
jsonError(rec, r, err)
resp := rec.Result()
if resp.StatusCode != http.StatusInternalServerError {
t.Errorf("expected status 500, got %d", resp.StatusCode)
}
body, _ := io.ReadAll(resp.Body)
if !strings.Contains(string(body), "test error") {
t.Errorf("expected error message in body, got %s", string(body))
}
}