test: fix some coverage issues, refactored some of the pagination logic to accomplish this (#3674)

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
Andrei Aaron
2025-12-23 19:06:13 +02:00
committed by GitHub
parent 4ad3fad3bc
commit 95b8d65c8a
6 changed files with 154 additions and 46 deletions
+5
View File
@@ -324,6 +324,11 @@ func validateStorageConfig(cfg *config.Config, logger zlog.Logger) error {
})
}
// Sort stores by route to ensure deterministic ordering
slices.SortFunc(allStores, func(a, b storeInfo) int {
return strings.Compare(a.route, b.route)
})
// Validate each store
for _, store := range allStores {
route := store.route
+38
View File
@@ -1266,6 +1266,44 @@ storage:
os.Args = []string{"cli_test", "verify", tmpfile}
err = cli.NewServerRootCmd().Execute()
So(err, ShouldBeNil)
// Default local store is inside substore (should be rejected)
// default is at /tmp/zot-parent/subdir, /a is at /tmp/zot-parent
content = `{"storage":{"rootDirectory":"/tmp/zot-parent/subdir",
"subPaths": {"/a": {"rootDirectory": "/tmp/zot-parent"}}},
"http":{"address":"127.0.0.1","port":"8080","realm":"zot",
"auth":{"htpasswd":{"path":"test/data/htpasswd"},"failDelay":1}}}`
err = os.WriteFile(tmpfile, []byte(content), 0o0600)
So(err, ShouldBeNil)
os.Args = []string{"cli_test", "verify", tmpfile}
err = cli.NewServerRootCmd().Execute()
So(err, ShouldNotBeNil)
// default storage is inside /a, validation reports this conflict
So(err.Error(), ShouldContainSubstring,
"invalid storage config, default storage root directory cannot be inside substore (route: /a) root directory")
// Default S3 store is inside substore, with S3, (should be rejected)
// default is at /zot-parent/subdir, /a is at /zot-parent
content = `{"storage":{"rootDirectory":"/zot-parent/subdir",
"storageDriver":{"name":"s3","rootdirectory":"/zot-parent/subdir","region":"us-east-2",
"bucket":"zot-storage","secure":true,"skipverify":false},
"dedupe":false,
"subPaths": {"/a": {"rootDirectory": "/zot-parent",
"storageDriver":{"name":"s3","rootdirectory":"/zot-parent","region":"us-east-2",
"bucket":"zot-storage","secure":true,"skipverify":false},
"dedupe":false}}},
"http":{"address":"127.0.0.1","port":"8080","realm":"zot",
"auth":{"htpasswd":{"path":"test/data/htpasswd"},"failDelay":1}}}`
err = os.WriteFile(tmpfile, []byte(content), 0o0600)
So(err, ShouldBeNil)
os.Args = []string{"cli_test", "verify", tmpfile}
err = cli.NewServerRootCmd().Execute()
So(err, ShouldNotBeNil)
// default storage is inside /a, validation reports this conflict
So(err.Error(), ShouldContainSubstring,
"invalid storage config, default storage root directory cannot be inside substore (route: /a) root directory")
})
Convey("Test verify w/ authorization and w/o authentication", t, func(c C) {