0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

test(sync): make sure sync doesn't write on shutdown (#1370)

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu 2023-04-19 21:34:41 +03:00 committed by GitHub
parent 0586c6227e
commit d818293cc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -487,6 +487,8 @@ func TestORAS(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(resp, ShouldNotBeEmpty) So(resp, ShouldNotBeEmpty)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -977,6 +979,8 @@ func TestPeriodically(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(destTagsList, ShouldNotResemble, srcTagsList) So(destTagsList, ShouldNotResemble, srcTagsList)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
}) })
} }
@ -1072,9 +1076,7 @@ func TestPermsDenied(t *testing.T) {
panic(err) panic(err)
} }
data, err := os.ReadFile(dctlr.Config.Log.Output) waitSyncFinish(dctlr.Config.Log.Output)
So(err, ShouldBeNil)
t.Logf("downstream log: %s", string(data))
}) })
} }
@ -1286,6 +1288,8 @@ func TestMandatoryAnnotations(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(resp, ShouldNotBeNil) So(resp, ShouldNotBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -1455,6 +1459,8 @@ func TestTLS(t *testing.T) {
if !found { if !found {
panic(errSync) panic(errSync)
} }
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -1531,6 +1537,8 @@ func TestBasicAuth(t *testing.T) {
} }
So(destTagsList, ShouldResemble, srcTagsList) So(destTagsList, ShouldResemble, srcTagsList)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
Convey("Verify sync basic auth with wrong file credentials", func() { Convey("Verify sync basic auth with wrong file credentials", func() {
@ -2393,6 +2401,7 @@ func TestSubPaths(t *testing.T) {
subPathDestDir := t.TempDir() subPathDestDir := t.TempDir()
destConfig.Storage.RootDirectory = destDir destConfig.Storage.RootDirectory = destDir
destConfig.Log.Output = path.Join(destDir, "sync.log")
destConfig.Storage.SubPaths = map[string]config.StorageConfig{ destConfig.Storage.SubPaths = map[string]config.StorageConfig{
subpath: { subpath: {
@ -2445,6 +2454,8 @@ func TestSubPaths(t *testing.T) {
binfo, err = os.Stat(path.Join(destDir, subpath)) binfo, err = os.Stat(path.Join(destDir, subpath))
So(binfo, ShouldBeNil) So(binfo, ShouldBeNil)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -2748,6 +2759,8 @@ func TestMultipleURLs(t *testing.T) {
} }
So(destTagsList, ShouldResemble, srcTagsList) So(destTagsList, ShouldResemble, srcTagsList)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -3985,6 +3998,15 @@ func TestError(t *testing.T) {
err = os.Chmod(localRepoPath, 0o000) err = os.Chmod(localRepoPath, 0o000)
So(err, ShouldBeNil) So(err, ShouldBeNil)
defer func() {
err = os.Chmod(localRepoPath, 0o755)
So(err, ShouldBeNil)
}()
resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
found, err := test.ReadLogFileAndSearchString(dctlr.Config.Log.Output, found, err := test.ReadLogFileAndSearchString(dctlr.Config.Log.Output,
"finished syncing", 15*time.Second) "finished syncing", 15*time.Second)
if err != nil { if err != nil {
@ -3999,10 +4021,6 @@ func TestError(t *testing.T) {
} }
So(found, ShouldBeTrue) So(found, ShouldBeTrue)
resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
}) })
} }
@ -4083,8 +4101,6 @@ func TestSignaturesOnDemand(t *testing.T) {
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")}) err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")})
So(err, ShouldBeNil) So(err, ShouldBeNil)
//
// test negative case // test negative case
cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig" cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig"
getCosignManifestURL := srcBaseURL + path.Join(constants.RoutePrefix, repoName, "manifests", cosignEncodedDigest) getCosignManifestURL := srcBaseURL + path.Join(constants.RoutePrefix, repoName, "manifests", cosignEncodedDigest)
@ -4451,6 +4467,8 @@ func TestSyncOnlyDiff(t *testing.T) {
} }
So(found, ShouldBeTrue) So(found, ShouldBeTrue)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -4502,6 +4520,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
destConfig.Extensions = &extconf.ExtensionConfig{} destConfig.Extensions = &extconf.ExtensionConfig{}
destConfig.Extensions.Search = nil destConfig.Extensions.Search = nil
destConfig.Extensions.Sync = syncConfig destConfig.Extensions.Sync = syncConfig
destConfig.Log.Output = path.Join(destDir, "sync.log")
dctlr := api.NewController(destConfig) dctlr := api.NewController(destConfig)
dcm := test.NewControllerManager(dctlr) dcm := test.NewControllerManager(dctlr)
@ -4591,6 +4610,8 @@ func TestSyncWithDiffDigest(t *testing.T) {
done <- true done <- true
So(isPopulated, ShouldBeTrue) So(isPopulated, ShouldBeTrue)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -4828,6 +4849,8 @@ func TestSyncSignaturesDiff(t *testing.T) {
} }
So(found, ShouldBeTrue) So(found, ShouldBeTrue)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -4897,6 +4920,8 @@ func TestOnlySignedFlag(t *testing.T) {
resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
Convey("Verify sync ondemand revokes unsigned images", t, func() { Convey("Verify sync ondemand revokes unsigned images", t, func() {
@ -4915,6 +4940,8 @@ func TestOnlySignedFlag(t *testing.T) {
resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
} }
@ -5025,7 +5052,7 @@ func TestSyncWithDestination(t *testing.T) {
defer dcm.StopServer() defer dcm.StopServer()
// give it time to set up sync // give it time to set up sync
waitSync(dctlr.Config.Storage.RootDirectory, testCase.expected) waitSyncFinish(dctlr.Config.Log.Output)
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testCase.expected + "/manifests/0.0.1") resp, err := destClient.R().Get(destBaseURL + "/v2/" + testCase.expected + "/manifests/0.0.1")
t.Logf("testcase: %#v", testCase) t.Logf("testcase: %#v", testCase)
@ -5176,6 +5203,8 @@ func TestSyncImageIndex(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(reflect.DeepEqual(syncedIndex, index), ShouldEqual, true) So(reflect.DeepEqual(syncedIndex, index), ShouldEqual, true)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
Convey("sync on demand", func() { Convey("sync on demand", func() {
@ -5207,7 +5236,7 @@ func TestSyncImageIndex(t *testing.T) {
func TestSyncOCIArtifactsWithTag(t *testing.T) { func TestSyncOCIArtifactsWithTag(t *testing.T) {
Convey("Verify syncing tagged OCI artifacts", t, func() { Convey("Verify syncing tagged OCI artifacts", t, func() {
updateDuration, _ := time.ParseDuration("5s") updateDuration, _ := time.ParseDuration("10s")
sctlr, srcBaseURL, _, _, _ := makeUpstreamServer(t, false, false) sctlr, srcBaseURL, _, _, _ := makeUpstreamServer(t, false, false)
@ -5345,14 +5374,16 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) {
panic(err) panic(err)
} }
// if !found { if !found {
data, err := os.ReadFile(dctlr.Config.Log.Output) data, err := os.ReadFile(dctlr.Config.Log.Output)
So(err, ShouldBeNil) So(err, ShouldBeNil)
t.Logf("downstream log: %s", string(data)) t.Logf("downstream log: %s", string(data))
// } }
So(found, ShouldBeTrue) So(found, ShouldBeTrue)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
Convey("sync on demand", func() { Convey("sync on demand", func() {
@ -5485,7 +5516,7 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) {
destConfig.Extensions.Search = nil destConfig.Extensions.Search = nil
destConfig.Extensions.Sync = syncConfig destConfig.Extensions.Sync = syncConfig
destConfig.Log.Output = path.Join(destDir, "zot.log") destConfig.Log.Output = path.Join(destDir, "sync.log")
dctlr := api.NewController(destConfig) dctlr := api.NewController(destConfig)
dcm := test.NewControllerManager(dctlr) dcm := test.NewControllerManager(dctlr)
@ -5522,6 +5553,8 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) {
Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, artifactDigest.String())) Get(destBaseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, artifactDigest.String()))
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
waitSyncFinish(dctlr.Config.Log.Output)
}) })
}) })
} }
@ -5808,3 +5841,13 @@ func pushBlob(url string, repoName string, buf []byte) godigest.Digest {
return digest return digest
} }
func waitSyncFinish(logPath string) bool {
found, err := test.ReadLogFileAndSearchString(logPath,
"finished syncing", 60*time.Second)
if err != nil {
panic(err)
}
return found
}