content/testsuite: pass context to hold lease

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2018-01-29 16:24:33 -08:00
parent c517a005b5
commit 3295bca5bf
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F
4 changed files with 18 additions and 14 deletions

View File

@ -72,12 +72,12 @@ func (mls *memoryLabelStore) Update(d digest.Digest, update map[string]string) (
}
func TestContent(t *testing.T) {
testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (content.Store, func() error, error) {
testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
cs, err := NewLabeledStore(root, newMemoryLabelStore())
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
return cs, func() error {
return ctx, cs, func() error {
return nil
}, nil
})

View File

@ -22,7 +22,7 @@ import (
)
// ContentSuite runs a test suite on the content store given a factory function.
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func() error, error)) {
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error)) {
t.Run("Writer", makeTest(t, name, storeFn, checkContentStoreWriter))
t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus))
t.Run("Resume", makeTest(t, name, storeFn, checkResumeWriter))
@ -34,7 +34,7 @@ func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, r
t.Run("Labels", makeTest(t, name, storeFn, checkLabels))
}
func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func() error, error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) {
func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) {
return func(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), name)
@ -44,7 +44,7 @@ func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root
}
defer os.RemoveAll(tmpDir)
cs, cleanup, err := storeFn(ctx, tmpDir)
ctx, cs, cleanup, err := storeFn(ctx, tmpDir)
if err != nil {
t.Fatal(err)
}

View File

@ -10,15 +10,18 @@ import (
"github.com/pkg/errors"
)
func newContentStore(ctx context.Context, root string) (content.Store, func() error, error) {
func newContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
client, err := New(address)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
ctx, releaselease, err := client.WithLease(ctx)
if err != nil {
return nil, nil, nil, err
}
cs := client.ContentStore()
return cs, func() error {
return ctx, cs, func() error {
statuses, err := cs.ListStatuses(ctx)
if err != nil {
return err
@ -28,6 +31,7 @@ func newContentStore(ctx context.Context, root string) (content.Store, func() er
return errors.Wrapf(err, "failed to abort %s", st.Ref)
}
}
releaselease()
return cs.Walk(ctx, func(info content.Info) error {
if err := cs.Delete(ctx, info.Digest); err != nil {
if errdefs.IsNotFound(err) {

View File

@ -17,19 +17,19 @@ import (
"github.com/pkg/errors"
)
func createContentStore(ctx context.Context, root string) (content.Store, func() error, error) {
func createContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
// TODO: Use mocked or in-memory store
cs, err := local.NewStore(root)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
return NewDB(db, cs, nil).ContentStore(), func() error {
return ctx, NewDB(db, cs, nil).ContentStore(), func() error {
return db.Close()
}, nil
}