Skip to content

Commit 91c3b8b

Browse files
stevvooeestesp
authored andcommitted
content/testsuite: pass context to hold lease
Signed-off-by: Stephen J Day <[email protected]>
1 parent c910b47 commit 91c3b8b

4 files changed

Lines changed: 18 additions & 14 deletions

File tree

content/local/store_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ func (mls *memoryLabelStore) Update(d digest.Digest, update map[string]string) (
7272
}
7373

7474
func TestContent(t *testing.T) {
75-
testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (content.Store, func() error, error) {
75+
testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
7676
cs, err := NewLabeledStore(root, newMemoryLabelStore())
7777
if err != nil {
78-
return nil, nil, err
78+
return nil, nil, nil, err
7979
}
80-
return cs, func() error {
80+
return ctx, cs, func() error {
8181
return nil
8282
}, nil
8383
})

content/testsuite/testsuite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
// ContentSuite runs a test suite on the content store given a factory function.
25-
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func() error, error)) {
25+
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error)) {
2626
t.Run("Writer", makeTest(t, name, storeFn, checkContentStoreWriter))
2727
t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus))
2828
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
3434
t.Run("Labels", makeTest(t, name, storeFn, checkLabels))
3535
}
3636

37-
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) {
37+
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) {
3838
return func(t *testing.T) {
3939
ctx := namespaces.WithNamespace(context.Background(), name)
4040

@@ -44,7 +44,7 @@ func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root
4444
}
4545
defer os.RemoveAll(tmpDir)
4646

47-
cs, cleanup, err := storeFn(ctx, tmpDir)
47+
ctx, cs, cleanup, err := storeFn(ctx, tmpDir)
4848
if err != nil {
4949
t.Fatal(err)
5050
}

content_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import (
1010
"github.com/pkg/errors"
1111
)
1212

13-
func newContentStore(ctx context.Context, root string) (content.Store, func() error, error) {
13+
func newContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
1414
client, err := New(address)
1515
if err != nil {
16-
return nil, nil, err
16+
return nil, nil, nil, err
17+
}
18+
ctx, releaselease, err := client.WithLease(ctx)
19+
if err != nil {
20+
return nil, nil, nil, err
1721
}
18-
1922
cs := client.ContentStore()
2023

21-
return cs, func() error {
24+
return ctx, cs, func() error {
2225
statuses, err := cs.ListStatuses(ctx)
2326
if err != nil {
2427
return err
@@ -28,6 +31,7 @@ func newContentStore(ctx context.Context, root string) (content.Store, func() er
2831
return errors.Wrapf(err, "failed to abort %s", st.Ref)
2932
}
3033
}
34+
releaselease()
3135
return cs.Walk(ctx, func(info content.Info) error {
3236
if err := cs.Delete(ctx, info.Digest); err != nil {
3337
if errdefs.IsNotFound(err) {

metadata/content_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ import (
1717
"github.com/pkg/errors"
1818
)
1919

20-
func createContentStore(ctx context.Context, root string) (content.Store, func() error, error) {
20+
func createContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
2121
// TODO: Use mocked or in-memory store
2222
cs, err := local.NewStore(root)
2323
if err != nil {
24-
return nil, nil, err
24+
return nil, nil, nil, err
2525
}
2626

2727
db, err := bolt.Open(filepath.Join(root, "metadata.db"), 0660, nil)
2828
if err != nil {
29-
return nil, nil, err
29+
return nil, nil, nil, err
3030
}
3131

32-
return NewDB(db, cs, nil).ContentStore(), func() error {
32+
return ctx, NewDB(db, cs, nil).ContentStore(), func() error {
3333
return db.Close()
3434
}, nil
3535
}

0 commit comments

Comments
 (0)