|
| 1 | +package conformance |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "net/http" |
| 6 | + "strconv" |
| 7 | + |
| 8 | + "github.com/bloodorangeio/reggie" |
| 9 | + g "github.com/onsi/ginkgo" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | +) |
| 12 | + |
| 13 | +var test06TagsList = func() { |
| 14 | + g.Context("Tags List", func() { |
| 15 | + g.Specify("GET request to list tags should yield 200 response", func() { |
| 16 | + req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list") |
| 17 | + resp, err := client.Do(req) |
| 18 | + Expect(err).To(BeNil()) |
| 19 | + Expect(resp.StatusCode()).To(Equal(http.StatusOK)) |
| 20 | + lastResponse = resp |
| 21 | + tagList := &TagList{} |
| 22 | + jsonData := []byte(resp.String()) |
| 23 | + err = json.Unmarshal(jsonData, tagList) |
| 24 | + Expect(err).To(BeNil()) |
| 25 | + numTags = len(tagList.Tags) |
| 26 | + }) |
| 27 | + |
| 28 | + g.Specify("GET request to manifest URL (tag) should yield 200 response", func() { |
| 29 | + tl := &TagList{} |
| 30 | + jsonData := lastResponse.Body() |
| 31 | + err := json.Unmarshal(jsonData, tl) |
| 32 | + Expect(err).To(BeNil()) |
| 33 | + Expect(tl.Tags).ToNot(BeEmpty()) |
| 34 | + req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<reference>", |
| 35 | + reggie.WithReference(tl.Tags[0])). |
| 36 | + SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json") |
| 37 | + resp, err := client.Do(req) |
| 38 | + Expect(err).To(BeNil()) |
| 39 | + Expect(resp.StatusCode()).To(Equal(http.StatusOK)) |
| 40 | + }) |
| 41 | + |
| 42 | + g.Specify("GET number of tags should be limitable by `n` query parameter", func() { |
| 43 | + numResults := numTags / 2 |
| 44 | + req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list"). |
| 45 | + SetQueryParam("n", strconv.Itoa(numResults)) |
| 46 | + resp, err := client.Do(req) |
| 47 | + Expect(err).To(BeNil()) |
| 48 | + Expect(resp.StatusCode()).To(Equal(http.StatusOK)) |
| 49 | + jsonData := resp.Body() |
| 50 | + tagList := &TagList{} |
| 51 | + err = json.Unmarshal(jsonData, tagList) |
| 52 | + Expect(err).To(BeNil()) |
| 53 | + Expect(len(tagList.Tags)).To(Equal(numResults)) |
| 54 | + lastTagList = *tagList |
| 55 | + }) |
| 56 | + |
| 57 | + g.Specify("GET start of tag is set by `last` query parameter", func() { |
| 58 | + numResults := numTags / 2 |
| 59 | + req := client.NewRequest(reggie.GET, "/v2/<name>/tags/list"). |
| 60 | + SetQueryParam("n", strconv.Itoa(numResults)). |
| 61 | + SetQueryParam("last", lastTagList.Tags[numResults-1]) |
| 62 | + resp, err := client.Do(req) |
| 63 | + Expect(err).To(BeNil()) |
| 64 | + Expect(resp.StatusCode()).To(Equal(http.StatusOK)) |
| 65 | + jsonData := resp.Body() |
| 66 | + tagList := &TagList{} |
| 67 | + err = json.Unmarshal(jsonData, tagList) |
| 68 | + Expect(err).To(BeNil()) |
| 69 | + Expect(tagList.Tags).To(ContainElement("test3")) |
| 70 | + }) |
| 71 | + }) |
| 72 | +} |
0 commit comments