Signed-off-by: Sameer Gupta <sameergupta4873@gmail.com>
| ... | ... |
@@ -50,14 +50,3 @@ func (s *DockerAPISuite) TestAPIErrorJSON(c *testing.T) {
|
| 50 | 50 |
assert.NilError(c, err) |
| 51 | 51 |
assert.Check(c, is.Contains(getErrorMessage(c, b), "config cannot be empty")) |
| 52 | 52 |
} |
| 53 |
- |
|
| 54 |
-func (s *DockerAPISuite) TestAPIErrorNotFoundJSON(c *testing.T) {
|
|
| 55 |
- // 404 is a different code path to normal errors, so test separately |
|
| 56 |
- httpResp, body, err := request.Get(testutil.GetContext(c), "/notfound", request.JSON) |
|
| 57 |
- assert.NilError(c, err) |
|
| 58 |
- assert.Equal(c, httpResp.StatusCode, http.StatusNotFound) |
|
| 59 |
- assert.Assert(c, is.Contains(httpResp.Header.Get("Content-Type"), "application/json"))
|
|
| 60 |
- b, err := request.ReadBody(body) |
|
| 61 |
- assert.NilError(c, err) |
|
| 62 |
- assert.Equal(c, getErrorMessage(c, b), "page not found") |
|
| 63 |
-} |
| 64 | 53 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+package system |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "net/http" |
|
| 4 |
+ "testing" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/moby/moby/api/types/common" |
|
| 7 |
+ "github.com/moby/moby/v2/internal/testutil/request" |
|
| 8 |
+ "gotest.tools/v3/assert" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+func TestAPIErrorNotFoundJSON(t *testing.T) {
|
|
| 12 |
+ ctx := setupTest(t) |
|
| 13 |
+ |
|
| 14 |
+ // 404 is a different code path to normal errors, so test separately |
|
| 15 |
+ httpResp, _, err := request.Get(ctx, "/notfound", request.JSON) |
|
| 16 |
+ assert.NilError(t, err) |
|
| 17 |
+ assert.Equal(t, httpResp.StatusCode, http.StatusNotFound) |
|
| 18 |
+ |
|
| 19 |
+ var respErr common.ErrorResponse |
|
| 20 |
+ assert.NilError(t, request.ReadJSONResponse(httpResp, &respErr)) |
|
| 21 |
+ assert.Error(t, respErr, "page not found") |
|
| 22 |
+} |