Merge pull request #4040 from thaJeztah/move_api_errors
This commit is contained in:
commit
612ad42609
14 changed files with 367 additions and 289 deletions
|
@ -339,7 +339,7 @@ func TestCatalogAPI(t *testing.T) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, v2.ErrorCodePaginationNumberInvalid)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
||||
|
||||
// -----------------------------------
|
||||
// Case No. 6: request n > maxentries but <= total catalog
|
||||
|
@ -360,7 +360,7 @@ func TestCatalogAPI(t *testing.T) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, v2.ErrorCodePaginationNumberInvalid)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
||||
|
||||
// -----------------------------------
|
||||
// Case No. 7: n = 0
|
||||
|
@ -409,7 +409,7 @@ func TestCatalogAPI(t *testing.T) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, v2.ErrorCodePaginationNumberInvalid)
|
||||
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
||||
|
||||
// -----------------------------------
|
||||
// Case No. 9: n = 5, max = 5, total catalog = 4
|
||||
|
@ -504,13 +504,13 @@ func TestTagsAPI(t *testing.T) {
|
|||
name: "negative n query parameter",
|
||||
queryParams: url.Values{"n": []string{"-1"}},
|
||||
expectedStatusCode: http.StatusBadRequest,
|
||||
expectedBodyErr: &v2.ErrorCodePaginationNumberInvalid,
|
||||
expectedBodyErr: &errcode.ErrorCodePaginationNumberInvalid,
|
||||
},
|
||||
{
|
||||
name: "non integer n query parameter",
|
||||
queryParams: url.Values{"n": []string{"foo"}},
|
||||
expectedStatusCode: http.StatusBadRequest,
|
||||
expectedBodyErr: &v2.ErrorCodePaginationNumberInvalid,
|
||||
expectedBodyErr: &errcode.ErrorCodePaginationNumberInvalid,
|
||||
},
|
||||
{
|
||||
name: "1st page",
|
||||
|
@ -900,7 +900,7 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "bad layer push", resp, http.StatusBadRequest)
|
||||
checkBodyHasErrorCodes(t, "bad layer push", resp, v2.ErrorCodeDigestInvalid)
|
||||
checkBodyHasErrorCodes(t, "bad layer push", resp, errcode.ErrorCodeDigestInvalid)
|
||||
|
||||
// -----------------------------------------
|
||||
// Do layer push with an empty body and correct digest
|
||||
|
@ -1342,7 +1342,7 @@ func TestManifestAPI_DeleteTag_Unknown(t *testing.T) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, msg, resp, http.StatusNotFound)
|
||||
checkBodyHasErrorCodes(t, msg, resp, v2.ErrorCodeManifestUnknown)
|
||||
checkBodyHasErrorCodes(t, msg, resp, errcode.ErrorCodeManifestUnknown)
|
||||
}
|
||||
|
||||
func TestManifestAPI_DeleteTag_ReadOnly(t *testing.T) {
|
||||
|
@ -1442,7 +1442,7 @@ func TestGetManifestWithStorageError(t *testing.T) {
|
|||
defer env1.Shutdown()
|
||||
|
||||
repo, _ := reference.WithName(repositoryWithManifestNotFound)
|
||||
testManifestWithStorageError(t, env1, repo, http.StatusNotFound, v2.ErrorCodeManifestUnknown)
|
||||
testManifestWithStorageError(t, env1, repo, http.StatusNotFound, errcode.ErrorCodeManifestUnknown)
|
||||
|
||||
repo, _ = reference.WithName(repositoryWithGenericStorageError)
|
||||
testManifestWithStorageError(t, env1, repo, http.StatusInternalServerError, errcode.ErrorCodeUnknown)
|
||||
|
@ -1528,7 +1528,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "getting non-existent manifest", resp, http.StatusNotFound)
|
||||
checkBodyHasErrorCodes(t, "getting non-existent manifest", resp, v2.ErrorCodeManifestUnknown)
|
||||
checkBodyHasErrorCodes(t, "getting non-existent manifest", resp, errcode.ErrorCodeManifestUnknown)
|
||||
|
||||
tagsURL, err := env.builder.BuildTagsURL(imageName)
|
||||
if err != nil {
|
||||
|
@ -1543,7 +1543,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
|
||||
// Check that we get an unknown repository error when asking for tags
|
||||
checkResponse(t, "getting unknown manifest tags", resp, http.StatusNotFound)
|
||||
checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, v2.ErrorCodeNameUnknown)
|
||||
checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, errcode.ErrorCodeNameUnknown)
|
||||
|
||||
// --------------------------------
|
||||
// Attempt to push manifest with missing config and missing layers
|
||||
|
@ -1574,10 +1574,10 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
resp = putManifest(t, "putting missing config manifest", manifestURL, schema2.MediaTypeManifest, manifest)
|
||||
defer resp.Body.Close()
|
||||
checkResponse(t, "putting missing config manifest", resp, http.StatusBadRequest)
|
||||
_, p, counts := checkBodyHasErrorCodes(t, "putting missing config manifest", resp, v2.ErrorCodeManifestBlobUnknown)
|
||||
_, p, counts := checkBodyHasErrorCodes(t, "putting missing config manifest", resp, errcode.ErrorCodeManifestBlobUnknown)
|
||||
|
||||
expectedCounts := map[errcode.ErrorCode]int{
|
||||
v2.ErrorCodeManifestBlobUnknown: 3,
|
||||
errcode.ErrorCodeManifestBlobUnknown: 3,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(counts, expectedCounts) {
|
||||
|
@ -1616,10 +1616,10 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
resp = putManifest(t, "putting missing layer manifest", manifestURL, schema2.MediaTypeManifest, manifest)
|
||||
defer resp.Body.Close()
|
||||
checkResponse(t, "putting missing layer manifest", resp, http.StatusBadRequest)
|
||||
_, p, counts = checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, v2.ErrorCodeManifestBlobUnknown)
|
||||
_, p, counts = checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, errcode.ErrorCodeManifestBlobUnknown)
|
||||
|
||||
expectedCounts = map[errcode.ErrorCode]int{
|
||||
v2.ErrorCodeManifestBlobUnknown: 2,
|
||||
errcode.ErrorCodeManifestBlobUnknown: 2,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(counts, expectedCounts) {
|
||||
|
@ -1840,10 +1840,10 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
|
|||
resp := putManifest(t, "putting missing manifest manifestlist", manifestURL, manifestlist.MediaTypeManifestList, manifestList)
|
||||
defer resp.Body.Close()
|
||||
checkResponse(t, "putting missing manifest manifestlist", resp, http.StatusBadRequest)
|
||||
_, p, counts := checkBodyHasErrorCodes(t, "putting missing manifest manifestlist", resp, v2.ErrorCodeManifestBlobUnknown)
|
||||
_, p, counts := checkBodyHasErrorCodes(t, "putting missing manifest manifestlist", resp, errcode.ErrorCodeManifestBlobUnknown)
|
||||
|
||||
expectedCounts := map[errcode.ErrorCode]int{
|
||||
v2.ErrorCodeManifestBlobUnknown: 1,
|
||||
errcode.ErrorCodeManifestBlobUnknown: 1,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(counts, expectedCounts) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue