Skip to content

Commit

Permalink
refactor(tests): Migrate some of the older tests to the new image-uti…
Browse files Browse the repository at this point in the history
…ls library (#1863)

Signed-off-by: Andrei Aaron <[email protected]>
  • Loading branch information
andaaron authored Oct 2, 2023
1 parent 2fd7bfc commit 99e29c0
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 282 deletions.
11 changes: 5 additions & 6 deletions pkg/cli/client/image_cmd_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
zlog "zotregistry.io/zot/pkg/log"
stypes "zotregistry.io/zot/pkg/storage/types"
test "zotregistry.io/zot/pkg/test/common"
"zotregistry.io/zot/pkg/test/deprecated"
. "zotregistry.io/zot/pkg/test/image-utils"
ociutils "zotregistry.io/zot/pkg/test/oci-utils"
"zotregistry.io/zot/pkg/test/signature"
Expand Down Expand Up @@ -1324,11 +1323,11 @@ func runDisplayIndexTests(baseURL string) {
actual := strings.TrimSpace(str)
// Actual cli output should be something similar to (order of images may differ):
// REPOSITORY TAG OS/ARCH DIGEST SIGNED SIZE
// repo multi-arch * 28665f71 false 1.5kB
// repo multi-arch * 4780eafe false 1.5kB
// linux/amd64 02e0ac42 false 644B
// windows/arm64/v6 5e09b7f9 false 444B
So(actual, ShouldContainSubstring, "REPOSITORY TAG OS/ARCH DIGEST SIGNED SIZE")
So(actual, ShouldContainSubstring, "repo multi-arch * 28665f71 false 1.5kB ")
So(actual, ShouldContainSubstring, "repo multi-arch * 4780eafe false 1.5kB ")
So(actual, ShouldContainSubstring, "linux/amd64 02e0ac42 false 644B ")
So(actual, ShouldContainSubstring, "windows/arm64/v6 5e09b7f9 false 506B")
})
Expand All @@ -1346,14 +1345,14 @@ func runDisplayIndexTests(baseURL string) {
actual := strings.TrimSpace(str)
// Actual cli output should be something similar to (order of images may differ):
// REPOSITORY TAG OS/ARCH DIGEST CONFIG SIGNED LAYERS SIZE
// repo multi-arch * 28665f71 false 1.5kB
// repo multi-arch * 4780eafe false 1.5kB
// linux/amd64 02e0ac42 58cc9abe false 644B
// cbb5b121 4B
// a00291e8 4B
// windows/arm64/v6 5e09b7f9 5132a1cd false 506B
// 7d08ce29 4B
So(actual, ShouldContainSubstring, "REPOSITORY TAG OS/ARCH DIGEST CONFIG SIGNED LAYERS SIZE")
So(actual, ShouldContainSubstring, "repo multi-arch * 28665f71 false 1.5kB")
So(actual, ShouldContainSubstring, "repo multi-arch * 4780eafe false 1.5kB")
So(actual, ShouldContainSubstring, "linux/amd64 02e0ac42 58cc9abe false 644B")
So(actual, ShouldContainSubstring, "cbb5b121 4B")
So(actual, ShouldContainSubstring, "a00291e8 4B")
Expand Down Expand Up @@ -2012,7 +2011,7 @@ func uploadTestMultiarch(baseURL string) {

// ------- Upload The multiarch image

multiarch := deprecated.GetMultiarchImageForImages([]Image{image1, image2}) //nolint:staticcheck
multiarch := CreateMultiarchWith().Images([]Image{image1, image2}).Build()

err := UploadMultiarchImage(multiarch, baseURL, "repo", "multi-arch")
So(err, ShouldBeNil)
Expand Down
109 changes: 15 additions & 94 deletions pkg/compliance/v1_0_0/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"zotregistry.io/zot/pkg/api/constants"
"zotregistry.io/zot/pkg/compliance"
test "zotregistry.io/zot/pkg/test/common"
"zotregistry.io/zot/pkg/test/deprecated"
"zotregistry.io/zot/pkg/test/image-utils"
)

Expand Down Expand Up @@ -486,46 +485,17 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)

cfg, layers, manifest, err := deprecated.GetImageComponents(1) //nolint:staticcheck
So(err, ShouldBeNil)
img := image.CreateDefaultImage()
digest = img.ManifestDescriptor.Digest

repoName := "repo7"
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, repoName, "test:1.0")
err = image.UploadImage(img, baseURL, repoName, "test:1.0")
So(err, ShouldBeNil)

content, err = json.Marshal(manifest)
err = image.UploadImage(img, baseURL, repoName, "test:1.0.1")
So(err, ShouldBeNil)
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, repoName, "test:1.0.1")
So(err, ShouldBeNil)

content = []byte("this is a blob5")
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

content, err = json.Marshal(manifest)
So(err, ShouldBeNil)
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, repoName, "test:2.0")
err = image.UploadImage(img, baseURL, repoName, "test:2.0")
So(err, ShouldBeNil)

// check/get by tag
Expand Down Expand Up @@ -593,23 +563,13 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
Convey("Pagination", func() {
_, _ = Print("\nPagination")

for index := 0; index <= 4; index++ {
cfg, layers, manifest, err := deprecated.GetImageComponents(1) //nolint:staticcheck
So(err, ShouldBeNil)
img := image.CreateDefaultImage()

for index := 0; index <= 4; index++ {
repoName := "page0"
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, repoName, fmt.Sprintf("test:%d.0", index))
So(err, ShouldBeNil)

content, err := json.Marshal(manifest)
err := image.UploadImage(
img, baseURL, repoName, fmt.Sprintf("test:%d.0", index))
So(err, ShouldBeNil)
digest := godigest.FromBytes(content)
So(digest, ShouldNotBeNil)
}

resp, err := resty.R().Get(baseURL + "/v2/page0/tags/list")
Expand Down Expand Up @@ -734,62 +694,23 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)

cfg, layers, manifest, err := deprecated.GetImageComponents(1) //nolint:staticcheck
So(err, ShouldBeNil)
img := image.CreateDefaultImage()
digest = img.ManifestDescriptor.Digest

// subpath firsttest
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, "firsttest/first", "test:1.0")
err = image.UploadImage(img, baseURL, "firsttest/first", "test:1.0")
So(err, ShouldBeNil)

content, err = json.Marshal(manifest)
So(err, ShouldBeNil)
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

// subpath secondtest
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, "secondtest/second", "test:1.0")
err = image.UploadImage(img, baseURL, "secondtest/second", "test:1.0")
So(err, ShouldBeNil)

content, err = json.Marshal(manifest)
So(err, ShouldBeNil)
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

content = []byte("this is a blob5")
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

// subpath firsttest
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, "firsttest/first", "test:2.0")
err = image.UploadImage(img, baseURL, "firsttest/first", "test:2.0")
So(err, ShouldBeNil)

content, err = json.Marshal(manifest)
So(err, ShouldBeNil)
digest = godigest.FromBytes(content)
So(digest, ShouldNotBeNil)

// subpath secondtest
err = image.UploadImage(
image.Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, "secondtest/second", "test:2.0")
err = image.UploadImage(img, baseURL, "secondtest/second", "test:2.0")
So(err, ShouldBeNil)

// check/get by tag
Expand Down
11 changes: 2 additions & 9 deletions pkg/extensions/extension_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"zotregistry.io/zot/pkg/api/config"
extconf "zotregistry.io/zot/pkg/extensions/config"
test "zotregistry.io/zot/pkg/test/common"
"zotregistry.io/zot/pkg/test/deprecated"
. "zotregistry.io/zot/pkg/test/image-utils"
)

Expand Down Expand Up @@ -59,19 +58,13 @@ func TestUIExtension(t *testing.T) {
So(found, ShouldBeTrue)
So(err, ShouldBeNil)

cfg, layers, manifest, err := deprecated.GetImageComponents(1) //nolint:staticcheck
So(err, ShouldBeNil)
image := CreateRandomImage()

repoName := "test-repo"
tagName := "test-tag"

// Upload a test image
err = UploadImage(
Image{
Config: cfg,
Layers: layers,
Manifest: manifest,
}, baseURL, repoName, tagName)
err = UploadImage(image, baseURL, repoName, tagName)
So(err, ShouldBeNil)

resp, err := resty.R().Get(baseURL + "/home")
Expand Down
13 changes: 4 additions & 9 deletions pkg/extensions/imagetrust/image_trust_disabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
package imagetrust_test

import (
"encoding/json"
"os"
"path"
"testing"

. "github.com/smartystreets/goconvey/convey"

"zotregistry.io/zot/pkg/extensions/imagetrust"
"zotregistry.io/zot/pkg/test/deprecated"
. "zotregistry.io/zot/pkg/test/image-utils"
)

func TestImageTrust(t *testing.T) {
Expand All @@ -28,13 +27,9 @@ func TestImageTrust(t *testing.T) {

repo := "repo"

image, err := deprecated.GetRandomImage() //nolint:staticcheck
So(err, ShouldBeNil)

manifestContent, err := json.Marshal(image.Manifest)
So(err, ShouldBeNil)

manifestDigest := image.Digest()
image := CreateRandomImage() //nolint:staticcheck
manifestContent := image.ManifestDescriptor.Data
manifestDigest := image.ManifestDescriptor.Digest

localImgTrustStore, err := imagetrust.NewLocalImageTrustStore(rootDir)
So(err, ShouldBeNil)
Expand Down
Loading

0 comments on commit 99e29c0

Please sign in to comment.