Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
33 lines
793 B
Go
33 lines
793 B
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/danielgtaylor/huma/v2"
|
|
|
|
"github.com/v10networks/nmon/internal/store"
|
|
)
|
|
|
|
func TestStoreErrorMapping(t *testing.T) {
|
|
s := &server{}
|
|
s.Logger = nil
|
|
for _, tc := range []struct {
|
|
err error
|
|
status int
|
|
detail string
|
|
}{
|
|
{fmt.Errorf("%w: slug taken", store.ErrConflict), http.StatusConflict, "slug taken"},
|
|
{fmt.Errorf("%w: bad kind", store.ErrInvalid), http.StatusUnprocessableEntity, "bad kind"},
|
|
{fmt.Errorf("wrapped: %w", store.ErrNotFound), http.StatusNotFound, "not found"},
|
|
} {
|
|
var se huma.StatusError
|
|
ok := errors.As(s.storeErr(tc.err), &se)
|
|
if !ok || se.GetStatus() != tc.status || se.Error() != tc.detail {
|
|
t.Errorf("%v: got %v, want %d %q", tc.err, se, tc.status, tc.detail)
|
|
}
|
|
}
|
|
}
|