storage: add context to storage.List (#321)

This commit is contained in:
Tyler Bui-Palsulich
2018-07-23 23:25:38 -04:00
committed by Rob j Loranger
parent db7a318a6f
commit 484b020556
10 changed files with 21 additions and 14 deletions
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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)
+3 -1
View File
@@ -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 {
+2 -2
View File
@@ -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())
})
+1 -2
View File
@@ -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
+3 -1
View File
@@ -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)
}
+2 -1
View File
@@ -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{})
+2 -1
View File
@@ -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)
+3 -1
View File
@@ -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]