Skip to content

Commit bbe424c

Browse files
committed
Allow range of response codes for manifest delete
Resolves #102. The revised test checks for one of three responses: 202 Accepted, 400 Bad Request, or 405 Method Not Allowed. If the response is 400 Bad Request, an additional check is triggered to verify an OCI-Conformant code is returned, in this case "UNSUPPORTED". Signed-off-by: Peter Engelbert <[email protected]>
1 parent 2ce66de commit bbe424c

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

conformance/08_manifest_delete_test.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,50 @@ import (
1111

1212
var test08ManifestDelete = func() {
1313
g.Context("Manifest Delete", func() {
14-
g.Specify("DELETE request to manifest URL (tag) MUST fail", func() {
14+
g.Specify("DELETE request to manifest should return 202, 400, or 405", func() {
1515
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
1616
reggie.WithReference(firstTag))
1717
resp, err := client.Do(req)
1818
Expect(err).To(BeNil())
19-
Expect(resp.StatusCode()).To(BeNumerically(">=", 400))
20-
Expect(resp.StatusCode()).To(BeNumerically("<", 500))
19+
Expect(resp.StatusCode()).To(SatisfyAny(
20+
Equal(http.StatusBadRequest),
21+
Equal(http.StatusMethodNotAllowed),
22+
Equal(http.StatusAccepted)))
23+
if resp.StatusCode() == http.StatusBadRequest {
24+
errorResponses, err := resp.Errors()
25+
Expect(err).To(BeNil())
26+
Expect(errorResponses).ToNot(BeEmpty())
27+
Expect(errorResponses[0].Code).To(Equal(errorCodes[UNSUPPORTED]))
28+
}
2129
})
2230

23-
g.Specify("GET request to manifest URL should reveal that delete failed", func() {
24-
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifestDigest)).
25-
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
26-
resp, err := client.Do(req)
27-
Expect(err).To(BeNil())
28-
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
29-
})
30-
31-
g.Specify("DELETE request to manifest URL (digest) should yield 202 response", func() {
31+
g.Specify("DELETE request to manifest (digest) should yield 202 response unless delete disallowed or already deleted", func() {
3232
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifestDigest))
3333
resp, err := client.Do(req)
3434
Expect(err).To(BeNil())
35-
Expect(resp.StatusCode()).To(Equal(http.StatusAccepted))
35+
// In the case that the previous request was accepted, this may or may not fail (which is ok)
36+
Expect(resp.StatusCode()).To(SatisfyAny(
37+
Equal(http.StatusBadRequest),
38+
Equal(http.StatusMethodNotAllowed),
39+
Equal(http.StatusAccepted),
40+
Equal(http.StatusNotFound),
41+
))
42+
if resp.StatusCode() == http.StatusBadRequest {
43+
errorResponses, err := resp.Errors()
44+
Expect(err).To(BeNil())
45+
Expect(errorResponses).ToNot(BeEmpty())
46+
Expect(errorResponses[0].Code).To(Equal(errorCodes[UNSUPPORTED]))
47+
}
3648
})
3749

38-
g.Specify("GET request to deleted manifest URL should yield 404 response", func() {
50+
g.Specify("GET request to deleted manifest URL should yield 404 response, unless delete is disallowed", func() {
3951
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifestDigest))
4052
resp, err := client.Do(req)
4153
Expect(err).To(BeNil())
42-
Expect(resp.StatusCode()).To(Equal(http.StatusNotFound))
54+
Expect(resp.StatusCode()).To(SatisfyAny(
55+
Equal(http.StatusNotFound),
56+
Equal(http.StatusOK),
57+
))
4358
})
4459

4560
g.Specify("GET request to tags list should reflect manifest deletion", func() {

conformance/reporter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ const (
3636
pre.fail-message {
3737
background: #f9a5a5;
3838
padding: 20px;
39+
margin-right: 10px;
3940
display: inline-block;
4041
border-radius: 4px;
4142
font-size: 1.25em;
43+
width: 94%;
44+
overflow-x: auto;
4245
}
4346
.green {
4447
background: #c8ffc8;

0 commit comments

Comments
 (0)