Something went wrong. Try again.
Simple homelab monitoring service
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package web
import ( "bytes" "errors" "net/http" "net/http/httptest" "net/url" "testing"
"log/slog")
func TestServerError(t *testing.T) { var b []byte buf := bytes.NewBuffer(b) app := &app{ logger: slog.New(slog.NewJSONHandler(buf, nil)), }
r := &http.Request{ URL: &url.URL{ Scheme: "https", Host: "example.org", }, Method: http.MethodPost, } w := httptest.NewRecorder()
app.serverError(w, r, errors.New("an error occurred"))
if w.Code != http.StatusInternalServerError { t.Errorf("got status code '%d', want '%d'", w.Code, http.StatusInternalServerError) }}
func TestNotFoundError(t *testing.T) { app := &app{ logger: slog.New(slog.DiscardHandler), }
w := &httptest.ResponseRecorder{} app.notFoundError(w)
if w.Code != http.StatusNotFound { t.Errorf("got status code '%d', want '%d'", w.Code, http.StatusNotFound) }}