0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-30 22:34:13 -05:00
zot/pkg/test/oci-utils/repo_test.go
Jan-Otto Kröpke f618b1d4ef
ci(deps): upgrade golangci-lint (#2556)
* ci(deps): upgrade golangci-lint

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* build(deps): removed disabled linters

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

* build(deps): go run github.com/daixiang0/gci@latest write .

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): go run golang.org/x/tools/cmd/goimports@latest -l -w .

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): go run github.com/bombsimon/wsl/v4/cmd...@latest -strict-append -test=true -fix ./...

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): go run github.com/catenacyber/perfsprint@latest -fix ./...

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): replace gomnd by mnd

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): make gqlgen

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build: Revert "build(deps): go run github.com/daixiang0/gci@latest write ."

This reverts commit 5bf8c42e1f.

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): go run github.com/daixiang0/gci@latest write -s 'standard' -s default -s 'prefix(zotregistry.dev/zot)' .

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* build(deps): make gqlgen

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: wsl issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: check-log issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: gci issues

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* fix: tests

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

---------

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>
2024-07-29 10:32:51 -07:00

115 lines
3.6 KiB
Go

package ociutils_test
import (
"context"
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
"zotregistry.dev/zot/pkg/meta/types"
"zotregistry.dev/zot/pkg/test/image-utils"
"zotregistry.dev/zot/pkg/test/mocks"
ociutils "zotregistry.dev/zot/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)
})
})
}