mirror of
https://github.com/gomods/athens
synced 2026-02-08 05:28:11 +00:00
storage: add context to storage.List (#321)
This commit is contained in:
committed by
Rob j Loranger
parent
db7a318a6f
commit
484b020556
@@ -24,7 +24,7 @@ func ListHandler(lister storage.Lister, eng *render.Engine) func(c buffalo.Conte
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
versions, err := lister.List(mod)
|
||||
versions, err := lister.List(c, mod)
|
||||
if storage.IsNotFoundError(err) {
|
||||
return c.Render(http.StatusNotFound, eng.JSON(err.Error()))
|
||||
} else if err != nil {
|
||||
|
||||
@@ -31,8 +31,8 @@ func (n noOpConnectedBackend) Exists(module, version string) bool {
|
||||
func (n noOpConnectedBackend) Get(module, vsn string) (*Version, error) {
|
||||
return n.backend.Get(module, vsn)
|
||||
}
|
||||
func (n noOpConnectedBackend) List(module string) ([]string, error) {
|
||||
return n.backend.List(module)
|
||||
func (n noOpConnectedBackend) List(ctx context.Context, module string) ([]string, error) {
|
||||
return n.backend.List(ctx, module)
|
||||
}
|
||||
func (n noOpConnectedBackend) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, info []byte) error {
|
||||
return n.backend.Save(ctx, module, version, mod, zip, info)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
func (l *storageImpl) List(module string) ([]string, error) {
|
||||
func (l *storageImpl) List(ctx context.Context, module string) ([]string, error) {
|
||||
loc := l.moduleLocation(module)
|
||||
fileInfos, err := afero.ReadDir(l.filesystem, loc)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,7 +41,7 @@ func (g *GcpTests) TestSaveGetListExistsRoundTrip() {
|
||||
})
|
||||
|
||||
g.T().Run("List module versions", func(t *testing.T) {
|
||||
versionList, err := store.List(g.module)
|
||||
versionList, err := store.List(g.context, g.module)
|
||||
r.NoError(err)
|
||||
r.Equal(1, len(versionList))
|
||||
r.Equal(g.version, versionList[0])
|
||||
@@ -84,7 +84,7 @@ func (g *GcpTests) TestNotFounds() {
|
||||
})
|
||||
|
||||
g.T().Run("List not found", func(t *testing.T) {
|
||||
_, err = store.List("nothing/to/see/here")
|
||||
_, err = store.List(g.context, "nothing/to/see/here")
|
||||
modNotFoundErr := athensStorage.ErrNotFound{Module: "nothing/to/see/here"}
|
||||
r.EqualError(modNotFoundErr, err.Error())
|
||||
})
|
||||
|
||||
@@ -9,8 +9,7 @@ import (
|
||||
|
||||
// List implements the (./pkg/storage).Lister interface
|
||||
// It returns a list of versions, if any, for a given module
|
||||
func (s *Storage) List(module string) ([]string, error) {
|
||||
ctx := context.Background()
|
||||
func (s *Storage) List(ctx context.Context, module string) ([]string, error) {
|
||||
paths, err := s.bucket.List(ctx, module)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package storage
|
||||
|
||||
import "context"
|
||||
|
||||
// Lister is the interface that lists versions of a specific baseURL & module
|
||||
type Lister interface {
|
||||
// List gets all the versions for the given baseURL & module.
|
||||
// It returns ErrNotFound if the module isn't found
|
||||
List(module string) ([]string, error)
|
||||
List(ctx context.Context, module string) ([]string, error)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package minio
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (l *storageImpl) List(module string) ([]string, error) {
|
||||
func (l *storageImpl) List(ctx context.Context, module string) ([]string, error) {
|
||||
dict := make(map[string]struct{})
|
||||
|
||||
doneCh := make(chan struct{})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/globalsign/mgo/bson"
|
||||
@@ -8,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// List lists all versions of a module
|
||||
func (s *ModuleStore) List(module string) ([]string, error) {
|
||||
func (s *ModuleStore) List(ctx context.Context, module string) ([]string, error) {
|
||||
c := s.s.DB(s.d).C(s.c)
|
||||
result := make([]storage.Module, 0)
|
||||
err := c.Find(bson.M{"module": module}).All(&result)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
)
|
||||
|
||||
// List lists all versions of a module
|
||||
func (r *ModuleStore) List(module string) ([]string, error) {
|
||||
func (r *ModuleStore) List(ctx context.Context, module string) ([]string, error) {
|
||||
result := make([]models.Module, 0)
|
||||
err := r.conn.Where("module = ?", module).All(&result)
|
||||
if err != nil {
|
||||
|
||||
@@ -100,7 +100,7 @@ func (d *TestSuites) testList(ts storage.TestSuite) {
|
||||
}
|
||||
// append version from save-get roundtrip
|
||||
versions = append([]string{d.version}, versions...)
|
||||
retVersions, err := ts.Storage().List(d.module)
|
||||
retVersions, err := ts.Storage().List(context.Background(), d.module)
|
||||
r.NoError(err, hrn)
|
||||
r.Equal(versions, retVersions, hrn)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func (d *TestSuites) testGetSaveListRoundTrip(ts storage.TestSuite) {
|
||||
r := d.Require()
|
||||
hrn := ts.StorageHumanReadableName()
|
||||
ts.Storage().Save(context.Background(), d.module, d.version, d.mod, bytes.NewReader(d.zip), d.info)
|
||||
listedVersions, err := ts.Storage().List(d.module)
|
||||
listedVersions, err := ts.Storage().List(context.Background(), d.module)
|
||||
r.NoError(err, hrn)
|
||||
r.Equal(1, len(listedVersions), hrn)
|
||||
retVersion := listedVersions[0]
|
||||
|
||||
Reference in New Issue
Block a user