/
04_management_test.go
174 lines (159 loc) · 6.28 KB
/
04_management_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package conformance
import (
"encoding/json"
"net/http"
"github.com/bloodorangeio/reggie"
g "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var test04ContentManagement = func() {
g.Context(titleContentManagement, func() {
const defaultTagName = "tagtest0"
var tagToDelete string
var numTags int
g.Context("Setup", func() {
g.Specify("Populate registry with test config blob", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/")
resp, err := client.Do(req)
Expect(err).To(BeNil())
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()).
SetHeader("Content-Length", configs[3].ContentLength).
SetHeader("Content-Type", "application/octet-stream").
SetQueryParam("digest", configs[3].Digest).
SetBody(configs[3].Content)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
})
g.Specify("Populate registry with test layer", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/")
resp, err := client.Do(req)
Expect(err).To(BeNil())
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()).
SetQueryParam("digest", layerBlobDigest).
SetHeader("Content-Type", "application/octet-stream").
SetHeader("Content-Length", layerBlobContentLength).
SetBody(layerBlobData)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
})
g.Specify("Populate registry with test tag", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
tagToDelete = defaultTagName
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(tagToDelete)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(manifests[3].Content)
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
})
g.Specify("Check how many tags there are before anything gets deleted", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
tagList := &TagList{}
jsonData := []byte(resp.String())
err = json.Unmarshal(jsonData, tagList)
Expect(err).To(BeNil())
numTags = len(tagList.Tags)
})
})
g.Context("Manifest delete", func() {
g.Specify("DELETE request to manifest tag should return 202, unless tag deletion is disallowed (400/405)", func() {
SkipIfDisabled(contentManagement)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
reggie.WithReference(tagToDelete))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
Equal(http.StatusBadRequest),
Equal(http.StatusAccepted),
Equal(http.StatusMethodNotAllowed)))
if resp.StatusCode() == http.StatusBadRequest {
errorResponses, err := resp.Errors()
Expect(err).To(BeNil())
Expect(errorResponses).ToNot(BeEmpty())
Expect(errorResponses[0].Code).To(Equal(errorCodes[UNSUPPORTED]))
}
})
g.Specify("DELETE request to manifest (digest) should yield 202 response unless already deleted", func() {
SkipIfDisabled(contentManagement)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[3].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
// In the case that the previous request was accepted, this may or may not fail (which is ok)
Expect(resp.StatusCode()).To(SatisfyAny(
Equal(http.StatusAccepted),
Equal(http.StatusNotFound),
))
})
g.Specify("GET request to deleted manifest URL should yield 404 response, unless delete is disallowed", func() {
SkipIfDisabled(contentManagement)
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[3].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
Equal(http.StatusNotFound),
Equal(http.StatusOK),
))
})
g.Specify("GET request to tags list should reflect manifest deletion", func() {
SkipIfDisabled(contentManagement)
req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
tagList := &TagList{}
jsonData := []byte(resp.String())
err = json.Unmarshal(jsonData, tagList)
Expect(err).To(BeNil())
Expect(len(tagList.Tags)).To(BeNumerically("<", numTags))
})
})
g.Context("Blob delete", func() {
g.Specify("DELETE request to blob URL should yield 202 response", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
// config blob
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(configs[3].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusAccepted))
// layer blob
req = client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(layerBlobDigest))
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusAccepted))
})
g.Specify("GET request to deleted blob URL should yield 404 response", func() {
SkipIfDisabled(contentManagement)
RunOnlyIf(runContentManagementSetup)
req := client.NewRequest(reggie.GET, "/v2/<name>/blobs/<digest>", reggie.WithDigest(configs[3].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusNotFound))
})
})
g.Context("Teardown", func() {
// TODO: delete blob+tag?
// No teardown required at this time for content management tests
})
})
}