mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
storage/gcp: fix lister prefix (#1172)
* storage/gcp: fix lister prefix * add slash to s3 * but really this time * account for windows
This commit is contained in:
@@ -21,6 +21,7 @@ func RunTests(t *testing.T, b storage.Backend, clearBackend func() error) {
|
||||
defer require.NoError(t, clearBackend(), "post-clearing backend failed")
|
||||
testNotFound(t, b)
|
||||
testList(t, b)
|
||||
testListSuffix(t, b)
|
||||
testDelete(t, b)
|
||||
testGet(t, b)
|
||||
testExists(t, b)
|
||||
@@ -55,6 +56,48 @@ func testNotFound(t *testing.T, b storage.Backend) {
|
||||
require.Equal(t, errors.KindNotFound, errors.Kind(err))
|
||||
}
|
||||
|
||||
// testListPrefixes makes sure that if you have two modules, such as
|
||||
// github.com/one/two and github.com/one/two-suffix, then the versions
|
||||
// should not be mixed just because they share a similar prefix.
|
||||
func testListSuffix(t *testing.T, b storage.Backend) {
|
||||
ctx := context.Background()
|
||||
|
||||
otherMod := "github.com/one/two-other"
|
||||
mock := getMockModule()
|
||||
err := b.Save(
|
||||
ctx,
|
||||
otherMod,
|
||||
"v0.9.0",
|
||||
mock.Mod,
|
||||
mock.Zip,
|
||||
mock.Info,
|
||||
)
|
||||
require.NoError(t, err, "Save for storage failed")
|
||||
modname := "github.com/one/two"
|
||||
versions := []string{"v1.1.0", "v1.2.0", "v1.3.0"}
|
||||
for _, version := range versions {
|
||||
mock := getMockModule()
|
||||
err := b.Save(
|
||||
ctx,
|
||||
modname,
|
||||
version,
|
||||
mock.Mod,
|
||||
mock.Zip,
|
||||
mock.Info,
|
||||
)
|
||||
require.NoError(t, err, "Save for storage failed")
|
||||
}
|
||||
defer func() {
|
||||
b.Delete(ctx, otherMod, "v0.9.0")
|
||||
for _, ver := range versions {
|
||||
b.Delete(ctx, modname, ver)
|
||||
}
|
||||
}()
|
||||
retVersions, err := b.List(ctx, modname)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, versions, retVersions)
|
||||
}
|
||||
|
||||
// testList tests that a storage Backend returns
|
||||
// the exact list of versions that are saved.
|
||||
func testList(t *testing.T, b storage.Backend) {
|
||||
|
||||
@@ -17,7 +17,8 @@ func (s *Storage) List(ctx context.Context, module string) ([]string, error) {
|
||||
ctx, span := observ.StartSpan(ctx, op.String())
|
||||
defer span.End()
|
||||
|
||||
it := s.bucket.Objects(ctx, &storage.Query{Prefix: module})
|
||||
modulePrefix := strings.TrimSuffix(module, "/") + "/@v"
|
||||
it := s.bucket.Objects(ctx, &storage.Query{Prefix: modulePrefix})
|
||||
paths := []string{}
|
||||
for {
|
||||
attrs, err := it.Next()
|
||||
|
||||
@@ -17,9 +17,10 @@ func (s *Storage) List(ctx context.Context, module string) ([]string, error) {
|
||||
ctx, span := observ.StartSpan(ctx, op.String())
|
||||
defer span.End()
|
||||
|
||||
modulePrefix := strings.TrimSuffix(module, "/") + "/@v"
|
||||
lsParams := &s3.ListObjectsInput{
|
||||
Bucket: aws.String(s.bucket),
|
||||
Prefix: aws.String(module),
|
||||
Prefix: aws.String(modulePrefix),
|
||||
}
|
||||
|
||||
loo, err := s.s3API.ListObjectsWithContext(ctx, lsParams)
|
||||
|
||||
Reference in New Issue
Block a user