MCPcopy Create free account
hub / github.com/MarioCarrion/todo-api-microservice-example / TestErrorCode

Function TestErrorCode

internal/errors_test.go:179–217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestErrorCode(t *testing.T) {
180 t.Parallel()
181
182 tests := []struct {
183 name string
184 code internal.ErrorCode
185 }{
186 {
187 name: "ErrorCodeUnknown",
188 code: internal.ErrorCodeUnknown,
189 },
190 {
191 name: "ErrorCodeNotFound",
192 code: internal.ErrorCodeNotFound,
193 },
194 {
195 name: "ErrorCodeInvalidArgument",
196 code: internal.ErrorCodeInvalidArgument,
197 },
198 }
199
200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
202 t.Parallel()
203
204 err := internal.NewErrorf(tt.code, "test error")
205
206 var ierr *internal.Error
207
208 if !errors.As(err, &ierr) {
209 t.Fatalf("expected error to be *internal.Error")
210 }
211
212 if ierr.Code() != tt.code {
213 t.Errorf("expected code %d, got %d", tt.code, ierr.Code())
214 }
215 })
216 }
217}

Callers

nothing calls this directly

Calls 2

CodeMethod · 0.95
NewErrorfFunction · 0.92

Tested by

no test coverage detected