Files
zot/pkg/test/oci-utils/repo_test.go
Luca Muscariello 2402296e9a fix: migrate to Go module v2 for proper semantic versioning (#3462)
* 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>
2025-10-16 22:43:47 -07:00

116 lines
3.7 KiB
Go

package ociutils_test
import (
"context"
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
"zotregistry.dev/zot/v2/pkg/meta/types"
"zotregistry.dev/zot/v2/pkg/test/image-utils"
"zotregistry.dev/zot/v2/pkg/test/mocks"
ociutils "zotregistry.dev/zot/v2/pkg/test/oci-utils"
)
var ErrTestFail = errors.New("fail")
func TestInitializeMetaDBErrors(t *testing.T) {
ctx := context.Background()
Convey("InitializeTestMetaDB", t, func() {
metaDB := mocks.MetaDBMock{
GetRepoMetaFn: func(ctx context.Context, repo string) (types.RepoMeta, error) {
return types.RepoMeta{
Statistics: map[string]types.DescriptorStatistics{},
Signatures: map[string]types.ManifestSignatures{},
Referrers: map[string][]types.ReferrerInfo{},
}, nil
},
}
Convey("Multiple repos same name", func() {
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB, ociutils.Repo{Name: "repo"}, ociutils.Repo{Name: "repo"})
So(err, ShouldNotBeNil)
})
Convey("Set Repo Ref fails", func() {
metaDB.SetRepoReferenceFn = func(ctx context.Context, repo, reference string, imageMeta types.ImageMeta) error {
return ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{Name: "repo", Images: []ociutils.RepoImage{{}}},
)
So(err, ShouldNotBeNil)
})
Convey("Set Repo Ref fails for manifest in index", func() {
metaDB.SetRepoReferenceFn = func(ctx context.Context, repo, reference string, imageMeta types.ImageMeta) error {
return ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{
Name: "repo",
MultiArchImages: []ociutils.RepoMultiArchImage{{MultiarchImage: image.CreateRandomMultiarch()}},
},
)
So(err, ShouldNotBeNil)
})
Convey("Set Repo Ref fails for index", func() {
count := 0
metaDB.SetRepoReferenceFn = func(ctx context.Context, repo, reference string, imageMeta types.ImageMeta) error {
if count == 1 {
return ErrTestFail
}
count++
return nil
}
multiarch := image.CreateMultiarchWith().Images([]image.Image{{}}).Build()
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{
Name: "repo",
MultiArchImages: []ociutils.RepoMultiArchImage{{MultiarchImage: multiarch}},
},
)
So(err, ShouldNotBeNil)
})
Convey("Get repo meta errors", func() {
metaDB.GetRepoMetaFn = func(ctx context.Context, repo string) (types.RepoMeta, error) {
return types.RepoMeta{}, ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{Name: "repo", Images: []ociutils.RepoImage{{}}},
)
So(err, ShouldNotBeNil)
})
Convey("Set repo meta errors", func() {
metaDB.SetRepoMetaFn = func(repo string, repoMeta types.RepoMeta) error {
return ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{Name: "repo", Images: []ociutils.RepoImage{{}}},
)
So(err, ShouldNotBeNil)
})
Convey("ToggleBookmarkRepo errors", func() {
metaDB.ToggleBookmarkRepoFn = func(ctx context.Context, repo string) (types.ToggleState, error) {
return types.NotChanged, ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{Name: "repo", Images: []ociutils.RepoImage{{}}, IsBookmarked: true},
)
So(err, ShouldNotBeNil)
})
Convey("ToggleStarRepo errors", func() {
metaDB.ToggleStarRepoFn = func(ctx context.Context, repo string) (types.ToggleState, error) {
return types.NotChanged, ErrTestFail
}
_, err := ociutils.InitializeTestMetaDB(ctx, metaDB,
ociutils.Repo{Name: "repo", Images: []ociutils.RepoImage{{}}, IsStarred: true},
)
So(err, ShouldNotBeNil)
})
})
}