refactor(pkg/test): split logic in pkg/test/common.go into multiple packages (#1861)

Which could be imported independently. See more details:
1. "zotregistry.io/zot/pkg/test/common" - currently used as
   tcommon "zotregistry.io/zot/pkg/test/common" - inside pkg/test
   test "zotregistry.io/zot/pkg/test/common" - in tests
   . "zotregistry.io/zot/pkg/test/common" - in tests
Decouple zb from code in test/pkg in order to keep the size small.

2. "zotregistry.io/zot/pkg/test/image-utils" - curently used as
   . "zotregistry.io/zot/pkg/test/image-utils"

3. "zotregistry.io/zot/pkg/test/deprecated" -  curently used as
   "zotregistry.io/zot/pkg/test/deprecated"
This one will bre replaced gradually by image-utils in the future.

4. "zotregistry.io/zot/pkg/test/signature" - (cosign + notation) use as
   "zotregistry.io/zot/pkg/test/signature"

5. "zotregistry.io/zot/pkg/test/auth" - (bearer + oidc)  curently used as
   authutils "zotregistry.io/zot/pkg/test/auth"

 6. "zotregistry.io/zot/pkg/test/oci-utils" -  curently used as
   ociutils "zotregistry.io/zot/pkg/test/oci-utils"

Some unused functions were removed, some were replaced, and in
a few cases specific funtions were moved to the files they were used in.

Added an interface for the StoreController, this reduces the number of imports
of the entire image store, decreasing binary size for tests.
If the zb code was still coupled with pkg/test, this would have reflected in zb size.

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron
2023-09-27 21:34:48 +03:00
committed by GitHub
parent c3801dc3d3
commit ba6f347d8d
82 changed files with 3362 additions and 3243 deletions
+24 -23
View File
@@ -33,8 +33,9 @@ import (
"zotregistry.io/zot/pkg/log"
"zotregistry.io/zot/pkg/storage"
"zotregistry.io/zot/pkg/storage/local"
"zotregistry.io/zot/pkg/test"
test "zotregistry.io/zot/pkg/test/common"
. "zotregistry.io/zot/pkg/test/image-utils"
"zotregistry.io/zot/pkg/test/signature"
)
type errReader int
@@ -203,7 +204,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
}
image := CreateRandomImage()
err = test.WriteImageToFileSystem(image, repo, tag, storeController)
err = WriteImageToFileSystem(image, repo, tag, storeController)
So(err, ShouldBeNil)
ctlr := api.NewController(conf)
@@ -323,7 +324,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
}
image := CreateRandomImage()
err = test.WriteImageToFileSystem(image, repo, tag, storeController)
err = WriteImageToFileSystem(image, repo, tag, storeController)
So(err, ShouldBeNil)
ctlr := api.NewController(conf)
@@ -341,13 +342,13 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
rootDir := t.TempDir()
test.NotationPathLock.Lock()
defer test.NotationPathLock.Unlock()
signature.NotationPathLock.Lock()
defer signature.NotationPathLock.Unlock()
test.LoadNotationPath(rootDir)
signature.LoadNotationPath(rootDir)
// generate a keypair
err = test.GenerateNotationCerts(rootDir, certName)
err = signature.GenerateNotationCerts(rootDir, certName)
So(err, ShouldBeNil)
// upload the certificate
@@ -364,7 +365,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
// sign the image
imageURL := fmt.Sprintf("localhost:%s/%s", port, fmt.Sprintf("%s:%s", repo, tag))
err = test.SignWithNotation(certName, imageURL, rootDir)
err = signature.SignWithNotation(certName, imageURL, rootDir)
So(err, ShouldBeNil)
found, err = test.ReadLogFileAndSearchString(logFile.Name(), "update signatures validity", 10*time.Second)
@@ -430,7 +431,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
}
image := CreateRandomImage()
err = test.WriteImageToFileSystem(image, repo, tag, storeController)
err = WriteImageToFileSystem(image, repo, tag, storeController)
So(err, ShouldBeNil)
ctlr := api.NewController(conf)
@@ -474,13 +475,13 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
rootDir := t.TempDir()
test.NotationPathLock.Lock()
defer test.NotationPathLock.Unlock()
signature.NotationPathLock.Lock()
defer signature.NotationPathLock.Unlock()
test.LoadNotationPath(rootDir)
signature.LoadNotationPath(rootDir)
// generate a keypair
err = test.GenerateNotationCerts(rootDir, certName)
err = signature.GenerateNotationCerts(rootDir, certName)
So(err, ShouldBeNil)
// upload the certificate
@@ -497,7 +498,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
// sign the image
imageURL := fmt.Sprintf("localhost:%s/%s", port, fmt.Sprintf("%s:%s", repo, tag))
err = test.SignWithNotation(certName, imageURL, rootDir)
err = signature.SignWithNotation(certName, imageURL, rootDir)
So(err, ShouldBeNil)
found, err = test.ReadLogFileAndSearchString(logFile.Name(), "update signatures validity", 10*time.Second)
@@ -592,7 +593,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
}
image := CreateRandomImage()
err = test.WriteImageToFileSystem(image, repo, tag, storeController)
err = WriteImageToFileSystem(image, repo, tag, storeController)
So(err, ShouldBeNil)
ctlr := api.NewController(conf)
@@ -854,15 +855,15 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
// Write image
image := CreateRandomImage()
err = test.WriteImageToFileSystem(image, repo, tag, storeController)
err = WriteImageToFileSystem(image, repo, tag, storeController)
So(err, ShouldBeNil)
// Write signature
signature := CreateImageWith().RandomLayers(1, 2).RandomConfig().Build()
sig := CreateImageWith().RandomLayers(1, 2).RandomConfig().Build()
So(err, ShouldBeNil)
ref, err := test.GetCosignSignatureTagForManifest(image.Manifest)
ref, err := signature.GetCosignSignatureTagForManifest(image.Manifest)
So(err, ShouldBeNil)
err = test.WriteImageToFileSystem(signature, repo, ref, storeController)
err = WriteImageToFileSystem(sig, repo, ref, storeController)
So(err, ShouldBeNil)
ctlr := api.NewController(conf)
@@ -950,13 +951,13 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
rootDir := t.TempDir()
test.NotationPathLock.Lock()
defer test.NotationPathLock.Unlock()
signature.NotationPathLock.Lock()
defer signature.NotationPathLock.Unlock()
test.LoadNotationPath(rootDir)
signature.LoadNotationPath(rootDir)
// generate Notation cert
err := test.GenerateNotationCerts(rootDir, "test")
err := signature.GenerateNotationCerts(rootDir, "test")
So(err, ShouldBeNil)
certificateContent, err := os.ReadFile(path.Join(rootDir, "notation/localkeys", "test.crt"))