Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: storage catalog #1872

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ require (
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rogpeppe/go-internal v1.3.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/tinylib/msgp v1.0.2 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
40 changes: 40 additions & 0 deletions pkg/storage/minio/cataloger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package minio

import (
"context"
"testing"

"github.com/gomods/athens/pkg/paths"
"github.com/gomods/athens/pkg/storage/minio/mocks"
"github.com/minio/minio-go/v6"
"github.com/stretchr/testify/require"
)

func TestCatalog(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mocks can we use a real minio set up like here

https://github.com/gomods/athens/blob/main/pkg/storage/minio/minio_test.go

token := "test-token"
bucketName := "test-bucket"
pageSize := 10

mockMinioCore := mocks.NewMinioCore(t)
mockMinioCore.On("ListObjectsV2", bucketName, "", token, false, "", 0, "").Return(minio.ListBucketV2Result{
Contents: []minio.ObjectInfo{
{
Key: "test-version/test.info",
},
},
}, nil)

st := &storageImpl{
minioCore: mockMinioCore,
bucketName: bucketName,
}

gotAllPathsParams, gotToken, gotErr := st.Catalog(context.Background(), token, pageSize)

expectedToken := ""
expectedAllPathsParams := []paths.AllPathParams{{Module: "/test.info", Version: "test-version"}}

require.NoError(t, gotErr)
require.Equal(t, expectedToken, gotToken)
require.Equal(t, expectedAllPathsParams, gotAllPathsParams)
}
8 changes: 7 additions & 1 deletion pkg/storage/minio/minio.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:generate mockery --inpackage=false --exported --name=minioCore

package minio

import (
Expand All @@ -10,9 +12,13 @@ import (
minio "github.com/minio/minio-go/v6"
)

type minioCore interface {
ListObjectsV2(bucketName, objectPrefix, continuationToken string, fetchOwner bool, delimiter string, maxkeys int, startAfter string) (minio.ListBucketV2Result, error)
}

type storageImpl struct {
minioClient *minio.Client
minioCore *minio.Core
minioCore minioCore
bucketName string
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/storage/minio/mocks/minioCore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.