forked from containrrr/watchtower
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from percona/PMM-13658-updates-server-error
PMM-13658 fix updates error response
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package update | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/containrrr/watchtower/pkg/types" | ||
) | ||
|
||
func TestHandleError(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
error error | ||
expectedStatus int | ||
}{ | ||
{ | ||
name: "no error returns OK", | ||
error: nil, | ||
expectedStatus: http.StatusOK, | ||
}, | ||
{ | ||
name: "validation error returns message", | ||
error: types.NewValidationError("no new image available"), | ||
expectedStatus: http.StatusPreconditionFailed, | ||
}, | ||
{ | ||
name: "generic server error", | ||
error: errors.New("server error"), | ||
expectedStatus: http.StatusInternalServerError, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
rr := httptest.NewRecorder() | ||
|
||
handleError(rr, tt.error) | ||
|
||
if status := rr.Result().StatusCode; status != tt.expectedStatus { | ||
t.Errorf("the handler wrote status code %d, expected: %d", status, tt.expectedStatus) | ||
} | ||
}) | ||
} | ||
} |