mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
refactor: update tests to use the newer API for creating test images (#2168)
- update cve tests - update scrub tests - update tests for parsing storage and loading into meta DB - update controller tests Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
@@ -40,7 +40,6 @@ import (
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
"zotregistry.io/zot/pkg/test/deprecated"
|
||||
. "zotregistry.io/zot/pkg/test/image-utils"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
ociutils "zotregistry.io/zot/pkg/test/oci-utils"
|
||||
@@ -1729,35 +1728,30 @@ func TestFixedTagsWithIndex(t *testing.T) {
|
||||
defer cm.StopServer()
|
||||
// push index with 2 manifests: one with vulns and one without
|
||||
vulnManifestCreated := time.Date(2010, 1, 1, 1, 1, 1, 1, time.UTC)
|
||||
vulnManifest, err := deprecated.GetVulnImageWithConfig(ispec.Image{ //nolint:staticcheck
|
||||
Created: &vulnManifestCreated,
|
||||
Platform: ispec.Platform{OS: "linux", Architecture: "amd64"},
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
vulnImageConfig := GetDefaultConfig()
|
||||
vulnImageConfig.Created = &vulnManifestCreated
|
||||
vulnImageConfig.Platform = ispec.Platform{OS: "linux", Architecture: "amd64"}
|
||||
vulnSingleArchImage := CreateImageWith().VulnerableLayers().VulnerableConfig(vulnImageConfig).Build()
|
||||
|
||||
fixedManifestCreated := time.Date(2010, 1, 1, 1, 1, 1, 1, time.UTC)
|
||||
fixedManifest, err := deprecated.GetImageWithConfig(ispec.Image{ //nolint:staticcheck
|
||||
Created: &fixedManifestCreated,
|
||||
Platform: ispec.Platform{OS: "windows", Architecture: "amd64"},
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
fixedDigest := fixedManifest.Digest()
|
||||
fixedImageConfig := GetDefaultConfig()
|
||||
fixedImageConfig.Created = &fixedManifestCreated
|
||||
fixedImageConfig.Platform = ispec.Platform{OS: "windows", Architecture: "amd64"}
|
||||
fixedSingleArchImage := CreateImageWith().DefaultLayers().ImageConfig(fixedImageConfig).Build()
|
||||
|
||||
multiArch := deprecated.GetMultiarchImageForImages([]Image{fixedManifest, //nolint:staticcheck
|
||||
vulnManifest})
|
||||
multiArchImage := CreateMultiarchWith().Images([]Image{vulnSingleArchImage, fixedSingleArchImage}).Build()
|
||||
|
||||
err = UploadMultiarchImage(multiArch, baseURL, "repo", "multi-arch-tag")
|
||||
err = UploadMultiarchImage(multiArchImage, baseURL, "repo", "multi-arch-tag")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// oldest vulnerability
|
||||
simpleVulnCreated := time.Date(2005, 1, 1, 1, 1, 1, 1, time.UTC)
|
||||
simpleVulnImg, err := deprecated.GetVulnImageWithConfig(ispec.Image{ //nolint:staticcheck
|
||||
Created: &simpleVulnCreated,
|
||||
Platform: ispec.Platform{OS: "windows", Architecture: "amd64"},
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
singleVulnImageConfig := GetDefaultConfig()
|
||||
singleVulnImageConfig.Created = &simpleVulnCreated
|
||||
singleVulnImageConfig.Platform = ispec.Platform{OS: "windows", Architecture: "amd64"}
|
||||
simpleVulnImage := CreateImageWith().VulnerableLayers().VulnerableConfig(singleVulnImageConfig).Build()
|
||||
|
||||
err = UploadImage(simpleVulnImg, baseURL, "repo", "vuln-img")
|
||||
err = UploadImage(simpleVulnImage, baseURL, "repo", "vuln-img")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Wait for trivy db to download
|
||||
@@ -1771,7 +1765,7 @@ func TestFixedTagsWithIndex(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(len(tagsInfo), ShouldEqual, 1)
|
||||
So(len(tagsInfo[0].Manifests), ShouldEqual, 1)
|
||||
So(tagsInfo[0].Manifests[0].Digest, ShouldResemble, fixedDigest)
|
||||
So(tagsInfo[0].Manifests[0].Digest, ShouldResemble, fixedSingleArchImage.ManifestDescriptor.Digest)
|
||||
|
||||
const query = `
|
||||
{
|
||||
@@ -1794,7 +1788,7 @@ func TestFixedTagsWithIndex(t *testing.T) {
|
||||
So(len(responseStruct.Results), ShouldEqual, 1)
|
||||
So(len(responseStruct.Results[0].Manifests), ShouldEqual, 1)
|
||||
fixedManifestResp := responseStruct.Results[0].Manifests[0]
|
||||
So(fixedManifestResp.Digest, ShouldResemble, fixedDigest.String())
|
||||
So(fixedManifestResp.Digest, ShouldResemble, fixedSingleArchImage.ManifestDescriptor.Digest.String())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
package trivy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
@@ -29,38 +27,17 @@ import (
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
storageTypes "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"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
|
||||
func generateTestImage(storeController storage.StoreController, image string) {
|
||||
repoName, tag := common.GetImageDirAndTag(image)
|
||||
func generateTestImage(storeController storage.StoreController, imageName string) {
|
||||
repoName, tag := common.GetImageDirAndTag(imageName)
|
||||
|
||||
config, layers, manifest, err := deprecated.GetImageComponents(10) //nolint:staticcheck
|
||||
So(err, ShouldBeNil)
|
||||
image := CreateRandomImage()
|
||||
|
||||
store := storeController.GetImageStore(repoName)
|
||||
err = store.InitRepo(repoName)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
for _, layerBlob := range layers {
|
||||
layerReader := bytes.NewReader(layerBlob)
|
||||
layerDigest := godigest.FromBytes(layerBlob)
|
||||
_, _, err = store.FullBlobUpload(repoName, layerReader, layerDigest)
|
||||
So(err, ShouldBeNil)
|
||||
}
|
||||
|
||||
configBlob, err := json.Marshal(config)
|
||||
So(err, ShouldBeNil)
|
||||
configReader := bytes.NewReader(configBlob)
|
||||
configDigest := godigest.FromBytes(configBlob)
|
||||
_, _, err = store.FullBlobUpload(repoName, configReader, configDigest)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
manifestBlob, err := json.Marshal(manifest)
|
||||
So(err, ShouldBeNil)
|
||||
_, _, err = store.PutImageManifest(repoName, tag, ispec.MediaTypeImageManifest, manifestBlob)
|
||||
err := WriteImageToFileSystem(
|
||||
image, repoName, tag, storeController)
|
||||
So(err, ShouldBeNil)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
. "zotregistry.io/zot/pkg/test/common"
|
||||
"zotregistry.io/zot/pkg/test/deprecated"
|
||||
. "zotregistry.io/zot/pkg/test/image-utils"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
@@ -97,8 +96,8 @@ func TestScanningByDigest(t *testing.T) {
|
||||
|
||||
simpleImage := CreateRandomImage()
|
||||
|
||||
multiArch := deprecated.GetMultiarchImageForImages([]Image{simpleImage, //nolint:staticcheck
|
||||
vulnImage})
|
||||
multiArch := CreateMultiarchWith().Images([]Image{simpleImage, //nolint:staticcheck
|
||||
vulnImage}).Build()
|
||||
|
||||
err := UploadMultiarchImage(multiArch, baseURL, "multi-arch", "multi-arch-tag")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Reference in New Issue
Block a user