(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestClassifyCommandFailure(t *testing.T) { |
| 57 | t.Run("classifies 401 and 403 management errors as auth", func(t *testing.T) { |
| 58 | for _, status := range []int{http.StatusUnauthorized, http.StatusForbidden} { |
| 59 | props := classifyCommandFailure(testManagementError{message: "auth error", status: status}) |
| 60 | assert.Equal(t, "false", props["success"]) |
| 61 | assert.Equal(t, "auth", props["error_class"]) |
| 62 | } |
| 63 | }) |
| 64 | |
| 65 | t.Run("classifies 400 and 422 management errors as validation", func(t *testing.T) { |
| 66 | for _, status := range []int{http.StatusBadRequest, http.StatusUnprocessableEntity} { |
| 67 | props := classifyCommandFailure(testManagementError{message: "validation error", status: status}) |
| 68 | assert.Equal(t, "validation", props["error_class"]) |
| 69 | } |
| 70 | }) |
| 71 | |
| 72 | t.Run("classifies 404 as not_found", func(t *testing.T) { |
| 73 | props := classifyCommandFailure(testManagementError{message: "not found", status: http.StatusNotFound}) |
| 74 | assert.Equal(t, "not_found", props["error_class"]) |
| 75 | }) |
| 76 | |
| 77 | t.Run("classifies 429 as rate_limit", func(t *testing.T) { |
| 78 | props := classifyCommandFailure(testManagementError{message: "rate limited", status: http.StatusTooManyRequests}) |
| 79 | assert.Equal(t, "rate_limit", props["error_class"]) |
| 80 | }) |
| 81 | |
| 82 | t.Run("classifies 5xx as api", func(t *testing.T) { |
| 83 | wrapped := fmt.Errorf("wrapped: %w", testManagementError{message: "server error", status: http.StatusServiceUnavailable}) |
| 84 | props := classifyCommandFailure(wrapped) |
| 85 | assert.Equal(t, "api", props["error_class"]) |
| 86 | }) |
| 87 | |
| 88 | t.Run("classifies non-management errors as unknown", func(t *testing.T) { |
| 89 | props := classifyCommandFailure(errors.New("boom")) |
| 90 | assert.Equal(t, "false", props["success"]) |
| 91 | assert.Equal(t, "unknown", props["error_class"]) |
| 92 | }) |
| 93 | |
| 94 | t.Run("classifies auth config errors as auth", func(t *testing.T) { |
| 95 | for _, err := range []error{ |
| 96 | config.ErrInvalidToken, |
| 97 | config.ErrMalformedToken, |
| 98 | config.ErrTokenMissingRequiredScopes{MissingScopes: []string{"read:users"}}, |
| 99 | } { |
| 100 | props := classifyCommandFailure(err) |
| 101 | assert.Equal(t, "auth", props["error_class"]) |
| 102 | } |
| 103 | }) |
| 104 | } |
| 105 | |
| 106 | func TestTestManagementErrorSatisfiesManagementError(t *testing.T) { |
| 107 | var _ management.Error = testManagementError{} |
nothing calls this directly
no test coverage detected