parse GHCR error format for errors

This commit is contained in:
Conor Sloan
2024-08-08 14:07:54 +01:00
parent 2bbf08d922
commit bebbbc6eee
4 changed files with 137 additions and 43 deletions
+34 -18
View File
@@ -26,16 +26,18 @@ const headMockNoExistingBlobs = (): object => {
// Simulate none of the blobs existing currently
return {
text() {
return 'Not Found'
return '{"errors": [{"code": "NOT_FOUND", "message": "blob not found."}]}'
},
status: 404
status: 404,
statusText: 'Not Found'
}
}
const headMockAllExistingBlobs = (): object => {
// Simulate all of the blobs existing currently
return {
status: 200
status: 200,
statusText: 'OK'
}
}
@@ -45,15 +47,17 @@ const headMockSomeExistingBlobs = (): object => {
// report one as existing
if (count === 1) {
return {
status: 200
status: 200,
statusText: 'OK'
}
} else {
// report all others are missing
return {
text() {
return 'Not Found'
return '{"errors": [{"code": "NOT_FOUND", "message": "blob not found."}]}'
},
status: 404
status: 404,
statusText: 'Not Found'
}
}
}
@@ -61,9 +65,11 @@ const headMockSomeExistingBlobs = (): object => {
const headMockFailure = (): object => {
return {
text() {
return 'Failed the head request'
// In this case we'll simulate a response which does not use the expected error format
return '503 Service Unavailable'
},
status: 503
status: 503,
statusText: 'Service Unavailable'
}
}
@@ -85,9 +91,11 @@ const postMockFailure = (): object => {
// Simulate failed initiation of uploads
return {
text() {
return 'Failed the post request'
// In this case we'll simulate a response which does not use the expected error format
return '503 Service Unavailable'
},
status: 503
status: 503,
statusText: 'Service Unavailable'
}
}
@@ -123,9 +131,10 @@ const putMockFailure = (): object => {
// Simulate fails upload of all blobs & manifest
return {
text() {
return 'Failed the put request'
return '{"errors": [{"code": "BAD_REQUEST", "message": "tag already exists."}]}'
},
status: 500
status: 400,
statusText: 'Bad Request'
}
}
@@ -134,9 +143,10 @@ const putMockFailureManifestUpload = (url: string): object => {
if (url.includes('manifest')) {
return {
text() {
return 'Failed the put request'
return '{"errors": [{"code": "BAD_REQUEST", "message": "tag already exists."}]}'
},
status: 500
status: 400,
statusText: 'Bad Request'
}
}
return {
@@ -343,7 +353,9 @@ describe('publishOCIArtifact', () => {
tarFile,
testManifest
)
).rejects.toThrow(/^Unexpected response from blob check for layer/)
).rejects.toThrow(
/^Unexpected 503 Service Unavailable response from check blob/
)
})
it('throws an error if initiating layer upload fails', async () => {
@@ -362,7 +374,9 @@ describe('publishOCIArtifact', () => {
tarFile,
testManifest
)
).rejects.toThrow('Unexpected response from POST upload 503')
).rejects.toThrow(
'Unexpected 503 Service Unavailable response from initiate layer upload. Response Body: 503 Service Unavailable.'
)
})
it('throws an error if the upload endpoint does not return a location', async () => {
@@ -406,7 +420,7 @@ describe('publishOCIArtifact', () => {
tarFile,
testManifest
)
).rejects.toThrow(/^Unexpected response from PUT upload 500/)
).rejects.toThrow(/^Unexpected 400 Bad Request response from layer/)
})
it('throws an error if a manifest upload fails', async () => {
@@ -431,7 +445,9 @@ describe('publishOCIArtifact', () => {
tarFile,
testManifest
)
).rejects.toThrow(/^Unexpected response from PUT manifest 500/)
).rejects.toThrow(
'Unexpected 400 Bad Request response from manifest upload. Errors: BAD_REQUEST - tag already exists.'
)
})
it('throws an error if reading one of the files fails', async () => {