content/testsuite: pass context to hold lease
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
c517a005b5
commit
3295bca5bf
@ -72,12 +72,12 @@ func (mls *memoryLabelStore) Update(d digest.Digest, update map[string]string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestContent(t *testing.T) {
|
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())
|
cs, err := NewLabeledStore(root, newMemoryLabelStore())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
return cs, func() error {
|
return ctx, cs, func() error {
|
||||||
return nil
|
return nil
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ContentSuite runs a test suite on the content store given a factory function.
|
// 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("Writer", makeTest(t, name, storeFn, checkContentStoreWriter))
|
||||||
t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus))
|
t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus))
|
||||||
t.Run("Resume", makeTest(t, name, storeFn, checkResumeWriter))
|
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))
|
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) {
|
return func(t *testing.T) {
|
||||||
ctx := namespaces.WithNamespace(context.Background(), name)
|
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)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
cs, cleanup, err := storeFn(ctx, tmpDir)
|
ctx, cs, cleanup, err := storeFn(ctx, tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,18 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"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)
|
client, err := New(address)
|
||||||
if err != nil {
|
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()
|
cs := client.ContentStore()
|
||||||
|
|
||||||
return cs, func() error {
|
return ctx, cs, func() error {
|
||||||
statuses, err := cs.ListStatuses(ctx)
|
statuses, err := cs.ListStatuses(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
return errors.Wrapf(err, "failed to abort %s", st.Ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
releaselease()
|
||||||
return cs.Walk(ctx, func(info content.Info) error {
|
return cs.Walk(ctx, func(info content.Info) error {
|
||||||
if err := cs.Delete(ctx, info.Digest); err != nil {
|
if err := cs.Delete(ctx, info.Digest); err != nil {
|
||||||
if errdefs.IsNotFound(err) {
|
if errdefs.IsNotFound(err) {
|
||||||
|
@ -17,19 +17,19 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"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
|
// TODO: Use mocked or in-memory store
|
||||||
cs, err := local.NewStore(root)
|
cs, err := local.NewStore(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil)
|
db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil)
|
||||||
if err != 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()
|
return db.Close()
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user