mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 11:37:56 +08:00
2402296e9a
* fix: migrate to Go module v2 for proper semantic versioning This change updates the module path from 'zotregistry.dev/zot' to 'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules. According to Go's module versioning requirements, major version v2+ must include the major version in the module path. The current module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x versions, making existing v2.x.x tags (like v2.1.8) unusable. Changes: - Updated go.mod module path to zotregistry.dev/zot/v2 - Updated all internal import paths across 280+ Go source files - Updated configuration files (golangcilint.yaml, gqlgen.yml) - Updated README.md Go reference badge This fix enables proper use of existing v2.x.x Git tags and allows external packages to import zot v2+ versions without compatibility errors. Resolves: Go module import compatibility for v2+ versions Fixes: #3071 Signed-off-by: Luca Muscariello <muscariello@ieee.org> * fix: regenerate GraphQL files with updated v2 import paths The gqlgen tool needs to regenerate the GraphQL schema files after the module path change to use the new v2 imports. Signed-off-by: Luca Muscariello <muscariello@ieee.org> --------- Signed-off-by: Luca Muscariello <muscariello@ieee.org>
161 lines
3.8 KiB
Go
161 lines
3.8 KiB
Go
package config_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"zotregistry.dev/zot/v2/pkg/api/config"
|
|
extconf "zotregistry.dev/zot/v2/pkg/extensions/config"
|
|
"zotregistry.dev/zot/v2/pkg/extensions/config/events"
|
|
)
|
|
|
|
func TestConfig(t *testing.T) {
|
|
Convey("Test config utils", t, func() {
|
|
firstStorageConfig := config.StorageConfig{
|
|
GC: true, Dedupe: true,
|
|
GCDelay: 1 * time.Minute, GCInterval: 1 * time.Hour,
|
|
}
|
|
secondStorageConfig := config.StorageConfig{
|
|
GC: true, Dedupe: true,
|
|
GCDelay: 1 * time.Minute, GCInterval: 1 * time.Hour,
|
|
}
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeTrue)
|
|
|
|
firstStorageConfig.GC = false
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
|
|
|
firstStorageConfig.GC = true
|
|
firstStorageConfig.Dedupe = false
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
|
|
|
firstStorageConfig.Dedupe = true
|
|
firstStorageConfig.GCDelay = 2 * time.Minute
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
|
|
|
firstStorageConfig.GCDelay = 1 * time.Minute
|
|
firstStorageConfig.GCInterval = 2 * time.Hour
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
|
|
|
firstStorageConfig.GCInterval = 1 * time.Hour
|
|
|
|
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeTrue)
|
|
|
|
isSame, err := config.SameFile("test-config", "test")
|
|
So(err, ShouldNotBeNil)
|
|
So(isSame, ShouldBeFalse)
|
|
|
|
dir1 := t.TempDir()
|
|
|
|
isSame, err = config.SameFile(dir1, "test")
|
|
So(err, ShouldNotBeNil)
|
|
So(isSame, ShouldBeFalse)
|
|
|
|
dir2 := t.TempDir()
|
|
|
|
isSame, err = config.SameFile(dir1, dir2)
|
|
So(err, ShouldBeNil)
|
|
So(isSame, ShouldBeFalse)
|
|
|
|
isSame, err = config.SameFile(dir1, dir1)
|
|
So(err, ShouldBeNil)
|
|
So(isSame, ShouldBeTrue)
|
|
})
|
|
|
|
Convey("Test DeepCopy() & Sanitize()", t, func() {
|
|
conf := config.New()
|
|
So(conf, ShouldNotBeNil)
|
|
|
|
authConfig := &config.AuthConfig{LDAP: (&config.LDAPConfig{}).SetBindPassword("oina")}
|
|
conf.HTTP.Auth = authConfig
|
|
|
|
So(func() { conf.Sanitize() }, ShouldNotPanic)
|
|
|
|
conf = conf.Sanitize()
|
|
So(conf.HTTP.Auth.LDAP.BindPassword(), ShouldEqual, "******")
|
|
|
|
// negative
|
|
obj := make(chan int)
|
|
err := config.DeepCopy(conf, obj)
|
|
So(err, ShouldNotBeNil)
|
|
err = config.DeepCopy(obj, conf)
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("Test IsRetentionEnabled()", t, func() {
|
|
conf := config.New()
|
|
So(conf.IsRetentionEnabled(), ShouldBeFalse)
|
|
|
|
conf.Storage.Retention.Policies = []config.RetentionPolicy{
|
|
{
|
|
Repositories: []string{"repo"},
|
|
},
|
|
}
|
|
|
|
So(conf.IsRetentionEnabled(), ShouldBeFalse)
|
|
|
|
policies := []config.RetentionPolicy{
|
|
{
|
|
Repositories: []string{"repo"},
|
|
KeepTags: []config.KeepTagsPolicy{
|
|
{
|
|
Patterns: []string{"tag"},
|
|
MostRecentlyPulledCount: 2,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
conf.Storage.Retention = config.ImageRetention{
|
|
Policies: policies,
|
|
}
|
|
|
|
So(conf.IsRetentionEnabled(), ShouldBeTrue)
|
|
|
|
subPaths := make(map[string]config.StorageConfig)
|
|
|
|
subPaths["/a"] = config.StorageConfig{
|
|
GC: true,
|
|
Retention: config.ImageRetention{
|
|
Policies: policies,
|
|
},
|
|
}
|
|
|
|
conf.Storage.SubPaths = subPaths
|
|
|
|
So(conf.IsRetentionEnabled(), ShouldBeTrue)
|
|
})
|
|
|
|
Convey("Test IsEventRecorderEnabled()", t, func() {
|
|
conf := config.New()
|
|
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
|
|
|
// Enable the event recorder
|
|
enable := true
|
|
conf.Extensions = &extconf.ExtensionConfig{}
|
|
conf.Extensions.Events = &events.Config{
|
|
Enable: &enable,
|
|
}
|
|
|
|
So(conf.IsEventRecorderEnabled(), ShouldBeTrue)
|
|
|
|
// Disabled scenario
|
|
disable := false
|
|
conf.Extensions.Events.Enable = &disable
|
|
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
|
|
|
// nil pointers
|
|
conf.Extensions.Events = nil
|
|
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
|
|
|
conf.Extensions = nil
|
|
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
|
})
|
|
}
|