feat: complete contract-driven business development and MySQL integration
This commit is contained in:
25
middleware/contextErrors_test.go
Normal file
25
middleware/contextErrors_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package middleware_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
apierrors "git.yuntuo.hk/k2safe/go-omni/errors"
|
||||
"git.yuntuo.hk/k2safe/go-omni/httpx"
|
||||
"git.yuntuo.hk/k2safe/go-omni/middleware"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContextErrorsPreservesExplicitBusinessFailures(t *testing.T) {
|
||||
business := apierrors.New(409, "CONFLICT", "conflict").WithCause(context.DeadlineExceeded)
|
||||
for _, tc := range []struct {
|
||||
err error
|
||||
code string
|
||||
}{{context.Canceled, "CANCELED"}, {fmt.Errorf("operation: %w", context.DeadlineExceeded), "TIMEOUT"}, {business, "CONFLICT"}} {
|
||||
err := middleware.ContextErrors("CANCELED", "TIMEOUT")(func(*httpx.Context) error { return tc.err })(nil)
|
||||
var result *apierrors.APIError
|
||||
if !errors.As(err, &result) || result.Code != tc.code || !errors.Is(err, tc.err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user