Files
zot/pkg/extensions/sync/sync_disabled_test.go
Andrei Aaron 9dfa7c3ae6 refactor(test): new apis for creating temporary files (#3605)
Replace MakeTempFile usage with MakeTempFilePath and MakeTempFileWithContent
helpers that automatically handle file lifecycle. This prevents resource
leaks by ensuring temporary files are properly closed.

Shoudld also make the tests easier to read.

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
2025-12-05 09:54:38 +02:00

68 lines
1.7 KiB
Go

//go:build !sync
package sync_test
import (
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/resty.v1"
"zotregistry.dev/zot/v2/pkg/api"
"zotregistry.dev/zot/v2/pkg/api/config"
extconf "zotregistry.dev/zot/v2/pkg/extensions/config"
syncconf "zotregistry.dev/zot/v2/pkg/extensions/config/sync"
test "zotregistry.dev/zot/v2/pkg/test/common"
)
func TestSyncExtension(t *testing.T) {
Convey("Make a new controller", t, func() {
conf := config.New()
port := test.GetFreePort()
baseURL := test.GetBaseURL(port)
globalDir := t.TempDir()
defaultValue := true
logPath := test.MakeTempFilePath(t, "zot-log.txt")
conf.HTTP.Port = port
conf.Storage.RootDirectory = globalDir
conf.Storage.Commit = true
conf.Extensions = &extconf.ExtensionConfig{}
conf.Extensions.Sync = &syncconf.Config{
Enable: &defaultValue,
}
conf.Log.Level = "warn"
conf.Log.Output = logPath
ctlr := api.NewController(conf)
ctlrManager := test.NewControllerManager(ctlr)
ctlrManager.StartAndWait(port)
defer ctlrManager.StopServer()
Convey("verify sync is skipped when binary doesn't include it", func() {
// image
resp, err := resty.R().
Head(baseURL + "/v2/" + "invalid" + "/manifests/invalid:0.0.2")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
// reference
resp, err = resty.R().
Head(baseURL + "/v2/" + "invalid" + "/manifests/sha256_digest.sig")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
data, err := os.ReadFile(logPath)
So(err, ShouldBeNil)
So(string(data), ShouldContainSubstring,
"skipping enabling sync extension because given zot binary doesn't include "+
"this feature,please build a binary that does so")
})
})
}