mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f0b3f5609
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
92 lines
1.7 KiB
Go
92 lines
1.7 KiB
Go
package errdefs
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestFromStatusCode(t *testing.T) {
|
|
testErr := fmt.Errorf("some error occurred")
|
|
|
|
testCases := []struct {
|
|
err error
|
|
status int
|
|
check func(error) bool
|
|
}{
|
|
{
|
|
err: testErr,
|
|
status: http.StatusNotFound,
|
|
check: IsNotFound,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusBadRequest,
|
|
check: IsInvalidParameter,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusConflict,
|
|
check: IsConflict,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusUnauthorized,
|
|
check: IsUnauthorized,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusServiceUnavailable,
|
|
check: IsUnavailable,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusForbidden,
|
|
check: IsForbidden,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusNotModified,
|
|
check: IsNotModified,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusNotImplemented,
|
|
check: IsNotImplemented,
|
|
},
|
|
{
|
|
err: testErr,
|
|
status: http.StatusInternalServerError,
|
|
check: IsSystem,
|
|
},
|
|
{
|
|
err: Unknown(testErr),
|
|
status: http.StatusInternalServerError,
|
|
check: IsUnknown,
|
|
},
|
|
{
|
|
err: DataLoss(testErr),
|
|
status: http.StatusInternalServerError,
|
|
check: IsDataLoss,
|
|
},
|
|
{
|
|
err: Deadline(testErr),
|
|
status: http.StatusInternalServerError,
|
|
check: IsDeadline,
|
|
},
|
|
{
|
|
err: Cancelled(testErr),
|
|
status: http.StatusInternalServerError,
|
|
check: IsCancelled,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(http.StatusText(tc.status), func(t *testing.T) {
|
|
err := FromStatusCode(tc.err, tc.status)
|
|
assert.Check(t, tc.check(err), "unexpected error-type %T", err)
|
|
})
|
|
}
|
|
}
|