zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/pkg/extensions/sync/sync_disabled_test.go (about) 1 //go:build !sync 2 // +build !sync 3 4 package sync_test 5 6 import ( 7 "os" 8 "testing" 9 10 . "github.com/smartystreets/goconvey/convey" 11 "gopkg.in/resty.v1" 12 13 "zotregistry.io/zot/pkg/api" 14 "zotregistry.io/zot/pkg/api/config" 15 extconf "zotregistry.io/zot/pkg/extensions/config" 16 syncconf "zotregistry.io/zot/pkg/extensions/config/sync" 17 test "zotregistry.io/zot/pkg/test/common" 18 ) 19 20 func TestSyncExtension(t *testing.T) { 21 Convey("Make a new controller", t, func() { 22 conf := config.New() 23 port := test.GetFreePort() 24 25 baseURL := test.GetBaseURL(port) 26 globalDir := t.TempDir() 27 defaultValue := true 28 29 logFile, err := os.CreateTemp(globalDir, "zot-log*.txt") 30 So(err, ShouldBeNil) 31 defer os.Remove(logFile.Name()) 32 33 conf.HTTP.Port = port 34 conf.Storage.RootDirectory = globalDir 35 conf.Storage.Commit = true 36 conf.Extensions = &extconf.ExtensionConfig{} 37 conf.Extensions.Sync = &syncconf.Config{ 38 Enable: &defaultValue, 39 } 40 conf.Log.Level = "warn" 41 conf.Log.Output = logFile.Name() 42 43 ctlr := api.NewController(conf) 44 ctlrManager := test.NewControllerManager(ctlr) 45 46 ctlrManager.StartAndWait(port) 47 defer ctlrManager.StopServer() 48 49 Convey("verify sync is skipped when binary doesn't include it", func() { 50 // image 51 resp, err := resty.R(). 52 Head(baseURL + "/v2/" + "invalid" + "/manifests/invalid:0.0.2") 53 So(err, ShouldBeNil) 54 So(resp, ShouldNotBeNil) 55 56 // reference 57 resp, err = resty.R(). 58 Head(baseURL + "/v2/" + "invalid" + "/manifests/sha256_digest.sig") 59 So(err, ShouldBeNil) 60 So(resp, ShouldNotBeNil) 61 62 data, err := os.ReadFile(logFile.Name()) 63 So(err, ShouldBeNil) 64 65 So(string(data), ShouldContainSubstring, 66 "skipping enabling sync extension because given zot binary doesn't include "+ 67 "this feature,please build a binary that does so") 68 }) 69 }) 70 }