mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 07:12:46 +01:00
30 lines
590 B
Go
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))
|
|
}
|
|
}
|