(t *testing.T)
| 134 | } |
| 135 | |
| 136 | func TestAutomationAndNetworkErrorHelpers(t *testing.T) { |
| 137 | t.Parallel() |
| 138 | |
| 139 | automationErr := NewAutomationValidationError(errors.New("bad automation request")) |
| 140 | if !errors.Is(automationErr, ErrAutomationValidation) { |
| 141 | t.Fatalf("NewAutomationValidationError() = %v, want ErrAutomationValidation", automationErr) |
| 142 | } |
| 143 | if got := NewAutomationValidationError(nil); got != nil { |
| 144 | t.Fatalf("NewAutomationValidationError(nil) = %v, want nil", got) |
| 145 | } |
| 146 | |
| 147 | networkErr := NewNetworkValidationError(errors.New("bad network request")) |
| 148 | if !errors.Is(networkErr, ErrNetworkValidation) { |
| 149 | t.Fatalf("NewNetworkValidationError() = %v, want ErrNetworkValidation", networkErr) |
| 150 | } |
| 151 | if got := NewNetworkValidationError(nil); got != nil { |
| 152 | t.Fatalf("NewNetworkValidationError(nil) = %v, want nil", got) |
| 153 | } |
| 154 | |
| 155 | if got := StatusForAutomationError(nil); got != http.StatusOK { |
| 156 | t.Fatalf("StatusForAutomationError(nil) = %d, want %d", got, http.StatusOK) |
| 157 | } |
| 158 | if got := StatusForAutomationError(automationpkg.ErrManagerNotRunning); got != http.StatusServiceUnavailable { |
| 159 | t.Fatalf("StatusForAutomationError(manager not running) = %d, want %d", got, http.StatusServiceUnavailable) |
| 160 | } |
| 161 | if got := StatusForAutomationError(automationpkg.ErrWebhookSignatureInvalid); got != http.StatusUnauthorized { |
| 162 | t.Fatalf("StatusForAutomationError(signature invalid) = %d, want %d", got, http.StatusUnauthorized) |
| 163 | } |
| 164 | |
| 165 | tests := []struct { |
| 166 | name string |
| 167 | err error |
| 168 | want int |
| 169 | }{ |
| 170 | {name: "nil", err: nil, want: http.StatusOK}, |
| 171 | {name: "validation", err: ErrNetworkValidation, want: http.StatusBadRequest}, |
| 172 | {name: "local peer missing", err: network.ErrLocalPeerNotFound, want: http.StatusNotFound}, |
| 173 | {name: "missing field", err: network.ErrMissingField, want: http.StatusBadRequest}, |
| 174 | {name: "default", err: errors.New("boom"), want: http.StatusInternalServerError}, |
| 175 | } |
| 176 | for _, tt := range tests { |
| 177 | t.Run(tt.name, func(t *testing.T) { |
| 178 | t.Parallel() |
| 179 | if got := StatusForNetworkError(tt.err); got != tt.want { |
| 180 | t.Fatalf("StatusForNetworkError(%v) = %d, want %d", tt.err, got, tt.want) |
| 181 | } |
| 182 | }) |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | func TestRespondErrorFallbackBranches(t *testing.T) { |
| 187 | t.Parallel() |
nothing calls this directly
no test coverage detected