MCPcopy Create free account
hub / github.com/compozy/agh / TestStatusForResourceError

Function TestStatusForResourceError

internal/api/core/resources_test.go:136–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestStatusForResourceError(t *testing.T) {
137 t.Parallel()
138
139 tests := []struct {
140 name string
141 err error
142 want int
143 }{
144 {name: "nil", err: nil, want: http.StatusOK},
145 {name: "validation", err: resources.ErrValidation, want: http.StatusUnprocessableEntity},
146 {name: "invalid scope", err: resources.ErrInvalidScopeBinding, want: http.StatusUnprocessableEntity},
147 {name: "codec mismatch", err: resources.ErrCodecTypeMismatch, want: http.StatusUnprocessableEntity},
148 {name: "permission denied", err: resources.ErrPermissionDenied, want: http.StatusForbidden},
149 {name: "direct mutation denied", err: resources.ErrDirectMutationNotAllowed, want: http.StatusForbidden},
150 {name: "conflict", err: resources.ErrConflict, want: http.StatusConflict},
151 {name: "stale source version", err: resources.ErrStaleSourceVersion, want: http.StatusConflict},
152 {name: "payload too large", err: resources.ErrPayloadTooLarge, want: http.StatusRequestEntityTooLarge},
153 {name: "rate limited", err: resources.ErrRateLimited, want: http.StatusTooManyRequests},
154 {name: "not found", err: resources.ErrNotFound, want: http.StatusNotFound},
155 {
156 name: "wrapped validation",
157 err: errors.Join(errors.New("boom"), resources.ErrValidation),
158 want: http.StatusUnprocessableEntity,
159 },
160 {name: "default", err: errors.New("boom"), want: http.StatusInternalServerError},
161 }
162
163 for _, tt := range tests {
164 t.Run(tt.name, func(t *testing.T) {
165 t.Parallel()
166 if got := StatusForResourceError(tt.err); got != tt.want {
167 t.Fatalf("StatusForResourceError(%v) = %d, want %d", tt.err, got, tt.want)
168 }
169 })
170 }
171}
172
173func TestParseResourceFilterPreservesListSemantics(t *testing.T) {
174 t.Parallel()

Callers

nothing calls this directly

Calls 2

StatusForResourceErrorFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected