Skip to content

Commit

Permalink
test: storage catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekatr committed May 8, 2023
1 parent a5f980d commit e4517de
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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) {
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)
}
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.

0 comments on commit e4517de

Please sign in to comment.