forked from opencontainers/distribution-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_discovery_test.go
196 lines (181 loc) · 6.43 KB
/
03_discovery_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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package conformance
import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
"github.com/bloodorangeio/reggie"
g "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var test03ContentDiscovery = func() {
g.Context(titleContentDiscovery, func() {
var numTags = 4
var tagList []string
g.Context("Setup", func() {
g.Specify("Populate registry with test blob", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
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", configs[2].Digest).
SetHeader("Content-Type", "application/octet-stream").
SetHeader("Content-Length", configs[2].ContentLength).
SetBody(configs[2].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(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
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 tags", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
for i := 0; i < numTags; i++ {
tag := fmt.Sprintf("test%d", i)
tagList = append(tagList, tag)
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(tag)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(manifests[2].Content)
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
}
req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list")
resp, err := client.Do(req)
tagList = getTagList(resp)
_ = err
})
g.Specify("Populate registry with test tags (no push)", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIfNot(runContentDiscoverySetup)
tagList = strings.Split(os.Getenv(envVarTagList), ",")
})
})
g.Context("Test content discovery endpoints", func() {
g.Specify("GET request to list tags should yield 200 response", func() {
SkipIfDisabled(contentDiscovery)
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))
numTags = len(tagList)
})
g.Specify("GET number of tags should be limitable by `n` query parameter", func() {
SkipIfDisabled(contentDiscovery)
numResults := numTags / 2
req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list").
SetQueryParam("n", strconv.Itoa(numResults))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
tagList = getTagList(resp)
Expect(err).To(BeNil())
Expect(len(tagList)).To(Equal(numResults))
})
g.Specify("GET start of tag is set by `last` query parameter", func() {
SkipIfDisabled(contentDiscovery)
numResults := numTags / 2
req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list").
SetQueryParam("n", strconv.Itoa(numResults))
resp, err := client.Do(req)
Expect(err).To(BeNil())
tagList = getTagList(resp)
req = client.NewRequest(reggie.GET, "/v2/<name>/tags/list").
SetQueryParam("n", strconv.Itoa(numResults)).
SetQueryParam("last", tagList[numResults-1])
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
Expect(err).To(BeNil())
Expect(len(tagList)).To(BeNumerically("<=", numResults))
Expect(tagList).To(ContainElement(tagList[numResults-1]))
})
})
g.Context("Teardown", func() {
if deleteManifestBeforeBlobs {
g.Specify("Delete created manifest & associated tags", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[2].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
})
}
g.Specify("Delete config blob created in tests", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(configs[2].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
})
g.Specify("Delete layer blob created in setup", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(layerBlobDigest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
})
if !deleteManifestBeforeBlobs {
g.Specify("Delete created manifest & associated tags", func() {
SkipIfDisabled(contentDiscovery)
RunOnlyIf(runContentDiscoverySetup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[2].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
})
}
})
})
}