Skip to content

Commit 78858b3

Browse files
committed
cleanup and lint for next version
1 parent be4a6c0 commit 78858b3

File tree

6 files changed

+65
-67
lines changed

6 files changed

+65
-67
lines changed

snapshot/localfile/localfile_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package localfile
33
import (
44
"archive/tar"
55
"bytes"
6-
"context"
76
"errors"
87
"os"
98
"path/filepath"
@@ -85,7 +84,7 @@ func TestNew_NilConfig(t *testing.T) {
8584

8685
func TestCreate(t *testing.T) {
8786
lf := newTestLF(t)
88-
ctx := context.Background()
87+
ctx := t.Context()
8988

9089
stream := makeTarGz(t, map[string][]byte{
9190
"cow.raw": []byte("disk data"),
@@ -120,7 +119,7 @@ func TestCreate(t *testing.T) {
120119

121120
func TestCreate_NoName(t *testing.T) {
122121
lf := newTestLF(t)
123-
ctx := context.Background()
122+
ctx := t.Context()
124123

125124
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
126125
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t)}, stream)
@@ -134,7 +133,7 @@ func TestCreate_NoName(t *testing.T) {
134133

135134
func TestCreate_DuplicateName(t *testing.T) {
136135
lf := newTestLF(t)
137-
ctx := context.Background()
136+
ctx := t.Context()
138137

139138
cfg := &types.SnapshotConfig{ID: testID(t), Name: "dup"}
140139

@@ -156,7 +155,7 @@ func TestCreate_DuplicateName(t *testing.T) {
156155

157156
func TestCreate_InvalidStream(t *testing.T) {
158157
lf := newTestLF(t)
159-
ctx := context.Background()
158+
ctx := t.Context()
160159

161160
_, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "bad"}, strings.NewReader("not gzip"))
162161
if err == nil {
@@ -168,7 +167,7 @@ func TestCreate_InvalidStream(t *testing.T) {
168167

169168
func TestList_Empty(t *testing.T) {
170169
lf := newTestLF(t)
171-
ctx := context.Background()
170+
ctx := t.Context()
172171

173172
result, err := lf.List(ctx)
174173
if err != nil {
@@ -181,7 +180,7 @@ func TestList_Empty(t *testing.T) {
181180

182181
func TestList(t *testing.T) {
183182
lf := newTestLF(t)
184-
ctx := context.Background()
183+
ctx := t.Context()
185184

186185
for _, name := range []string{"s1", "s2", "s3"} {
187186
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte(name)})
@@ -213,7 +212,7 @@ func TestList(t *testing.T) {
213212

214213
func TestInspect_ByID(t *testing.T) {
215214
lf := newTestLF(t)
216-
ctx := context.Background()
215+
ctx := t.Context()
217216

218217
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
219218
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "byid", Description: "desc"}, stream)
@@ -238,7 +237,7 @@ func TestInspect_ByID(t *testing.T) {
238237

239238
func TestInspect_ByName(t *testing.T) {
240239
lf := newTestLF(t)
241-
ctx := context.Background()
240+
ctx := t.Context()
242241

243242
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
244243
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "byname"}, stream)
@@ -257,7 +256,7 @@ func TestInspect_ByName(t *testing.T) {
257256

258257
func TestInspect_ByPrefix(t *testing.T) {
259258
lf := newTestLF(t)
260-
ctx := context.Background()
259+
ctx := t.Context()
261260

262261
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
263262
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "pfx"}, stream)
@@ -278,7 +277,7 @@ func TestInspect_ByPrefix(t *testing.T) {
278277

279278
func TestInspect_NotFound(t *testing.T) {
280279
lf := newTestLF(t)
281-
ctx := context.Background()
280+
ctx := t.Context()
282281

283282
_, err := lf.Inspect(ctx, "nonexistent")
284283
if err == nil {
@@ -293,7 +292,7 @@ func TestInspect_NotFound(t *testing.T) {
293292

294293
func TestDelete(t *testing.T) {
295294
lf := newTestLF(t)
296-
ctx := context.Background()
295+
ctx := t.Context()
297296

298297
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
299298
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "del"}, stream)
@@ -328,7 +327,7 @@ func TestDelete(t *testing.T) {
328327

329328
func TestDelete_ByID(t *testing.T) {
330329
lf := newTestLF(t)
331-
ctx := context.Background()
330+
ctx := t.Context()
332331

333332
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
334333
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "delid"}, stream)
@@ -347,7 +346,7 @@ func TestDelete_ByID(t *testing.T) {
347346

348347
func TestDelete_Multiple(t *testing.T) {
349348
lf := newTestLF(t)
350-
ctx := context.Background()
349+
ctx := t.Context()
351350

352351
var ids []string
353352
for _, name := range []string{"m1", "m2", "m3"} {
@@ -376,7 +375,7 @@ func TestDelete_Multiple(t *testing.T) {
376375

377376
func TestDelete_DuplicateRefs(t *testing.T) {
378377
lf := newTestLF(t)
379-
ctx := context.Background()
378+
ctx := t.Context()
380379

381380
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
382381
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "dedup"}, stream)
@@ -396,7 +395,7 @@ func TestDelete_DuplicateRefs(t *testing.T) {
396395

397396
func TestDelete_NotFound(t *testing.T) {
398397
lf := newTestLF(t)
399-
ctx := context.Background()
398+
ctx := t.Context()
400399

401400
_, err := lf.Delete(ctx, []string{"nonexistent"})
402401
if err == nil {
@@ -408,7 +407,7 @@ func TestDelete_NotFound(t *testing.T) {
408407

409408
func TestCreate_Inspect_Fields(t *testing.T) {
410409
lf := newTestLF(t)
411-
ctx := context.Background()
410+
ctx := t.Context()
412411

413412
stream := makeTarGz(t, map[string][]byte{"cow.raw": []byte("data")})
414413
cfg := &types.SnapshotConfig{
@@ -445,7 +444,7 @@ func TestCreate_Inspect_Fields(t *testing.T) {
445444

446445
func TestDelete_RecreateName(t *testing.T) {
447446
lf := newTestLF(t)
448-
ctx := context.Background()
447+
ctx := t.Context()
449448

450449
stream1 := makeTarGz(t, map[string][]byte{"f.txt": []byte("v1")})
451450
_, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "reuse"}, stream1)
@@ -476,7 +475,7 @@ func TestDelete_RecreateName(t *testing.T) {
476475

477476
func TestDataDir(t *testing.T) {
478477
lf := newTestLF(t)
479-
ctx := context.Background()
478+
ctx := t.Context()
480479

481480
stream := makeTarGz(t, map[string][]byte{"cow.raw": []byte("disk")})
482481
cfg := &types.SnapshotConfig{
@@ -513,7 +512,7 @@ func TestDataDir(t *testing.T) {
513512

514513
func TestDataDir_NotFound(t *testing.T) {
515514
lf := newTestLF(t)
516-
ctx := context.Background()
515+
ctx := t.Context()
517516

518517
_, _, err := lf.DataDir(ctx, "nonexistent")
519518
if err == nil {
@@ -526,7 +525,7 @@ func TestDataDir_NotFound(t *testing.T) {
526525

527526
func TestDataDir_ImageBlobIDsIsolation(t *testing.T) {
528527
lf := newTestLF(t)
529-
ctx := context.Background()
528+
ctx := t.Context()
530529

531530
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
532531
cfg := &types.SnapshotConfig{
@@ -563,7 +562,7 @@ func TestDataDir_ImageBlobIDsIsolation(t *testing.T) {
563562

564563
func TestRestore_ConfigRoundtrip(t *testing.T) {
565564
lf := newTestLF(t)
566-
ctx := context.Background()
565+
ctx := t.Context()
567566

568567
stream := makeTarGz(t, map[string][]byte{"cow.raw": []byte("disk")})
569568
cfg := &types.SnapshotConfig{
@@ -617,7 +616,7 @@ func TestRestore_ConfigRoundtrip(t *testing.T) {
617616

618617
func TestRestore_DataStream(t *testing.T) {
619618
lf := newTestLF(t)
620-
ctx := context.Background()
619+
ctx := t.Context()
621620

622621
wantContent := []byte("hello snapshot data")
623622
stream := makeTarGz(t, map[string][]byte{"state.json": wantContent})
@@ -660,7 +659,7 @@ func TestRestore_DataStream(t *testing.T) {
660659

661660
func TestRestore_CloseWaitsForGoroutine(t *testing.T) {
662661
lf := newTestLF(t)
663-
ctx := context.Background()
662+
ctx := t.Context()
664663

665664
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
666665
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "cw"}, stream)
@@ -684,7 +683,7 @@ func TestRestore_CloseWaitsForGoroutine(t *testing.T) {
684683

685684
func TestRestore_DoubleCloseNoPanic(t *testing.T) {
686685
lf := newTestLF(t)
687-
ctx := context.Background()
686+
ctx := t.Context()
688687

689688
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
690689
id, err := lf.Create(ctx, &types.SnapshotConfig{ID: testID(t), Name: "dc"}, stream)
@@ -705,7 +704,7 @@ func TestRestore_DoubleCloseNoPanic(t *testing.T) {
705704

706705
func TestRestore_ImageBlobIDsIsolation(t *testing.T) {
707706
lf := newTestLF(t)
708-
ctx := context.Background()
707+
ctx := t.Context()
709708

710709
stream := makeTarGz(t, map[string][]byte{"f.txt": []byte("x")})
711710
cfg := &types.SnapshotConfig{

utils/batch_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestForEach_AllSucceed(t *testing.T) {
12-
result := ForEach(context.Background(), []string{"a", "b", "c"}, func(_ context.Context, _ string) error {
12+
result := ForEach(t.Context(), []string{"a", "b", "c"}, func(_ context.Context, _ string) error {
1313
return nil
1414
})
1515

@@ -25,7 +25,7 @@ func TestForEach_AllSucceed(t *testing.T) {
2525
}
2626

2727
func TestForEach_AllFail(t *testing.T) {
28-
result := ForEach(context.Background(), []string{"x", "y"}, func(_ context.Context, id string) error {
28+
result := ForEach(t.Context(), []string{"x", "y"}, func(_ context.Context, id string) error {
2929
return fmt.Errorf("fail %s", id)
3030
})
3131

@@ -41,7 +41,7 @@ func TestForEach_AllFail(t *testing.T) {
4141
}
4242

4343
func TestForEach_PartialFailure(t *testing.T) {
44-
result := ForEach(context.Background(), []string{"ok", "fail", "ok2"}, func(_ context.Context, id string) error {
44+
result := ForEach(t.Context(), []string{"ok", "fail", "ok2"}, func(_ context.Context, id string) error {
4545
if id == "fail" {
4646
return fmt.Errorf("error on %s", id)
4747
}
@@ -57,7 +57,7 @@ func TestForEach_PartialFailure(t *testing.T) {
5757
}
5858

5959
func TestForEach_EmptyIDs(t *testing.T) {
60-
result := ForEach(context.Background(), nil, func(_ context.Context, _ string) error {
60+
result := ForEach(t.Context(), nil, func(_ context.Context, _ string) error {
6161
t.Fatal("should not be called")
6262
return nil
6363
})
@@ -78,7 +78,7 @@ func TestBatchResult_Err_NilForNoErrors(t *testing.T) {
7878
}
7979

8080
func TestForEach_SingleID(t *testing.T) {
81-
result := ForEach(context.Background(), []string{"only"}, func(_ context.Context, id string) error {
81+
result := ForEach(t.Context(), []string{"only"}, func(_ context.Context, id string) error {
8282
if id != "only" {
8383
t.Errorf("unexpected id: %s", id)
8484
}
@@ -93,7 +93,7 @@ func TestForEach_Concurrent(t *testing.T) {
9393
var peak atomic.Int32
9494
var cur atomic.Int32
9595

96-
result := ForEach(context.Background(), []string{"a", "b", "c", "d", "e"}, func(_ context.Context, _ string) error {
96+
result := ForEach(t.Context(), []string{"a", "b", "c", "d", "e"}, func(_ context.Context, _ string) error {
9797
n := cur.Add(1)
9898
for {
9999
old := peak.Load()
@@ -118,7 +118,7 @@ func TestForEach_WithConcurrencyLimit(t *testing.T) {
118118
var peak atomic.Int32
119119
var cur atomic.Int32
120120

121-
result := ForEach(context.Background(), []string{"a", "b", "c", "d", "e"}, func(_ context.Context, _ string) error {
121+
result := ForEach(t.Context(), []string{"a", "b", "c", "d", "e"}, func(_ context.Context, _ string) error {
122122
n := cur.Add(1)
123123
for {
124124
old := peak.Load()
@@ -143,7 +143,7 @@ func TestForEach_WithConcurrencyLimit(t *testing.T) {
143143
}
144144

145145
func TestForEach_IntItems(t *testing.T) {
146-
result := ForEach(context.Background(), []int{1, 2, 3}, func(_ context.Context, n int) error {
146+
result := ForEach(t.Context(), []int{1, 2, 3}, func(_ context.Context, n int) error {
147147
if n == 2 {
148148
return fmt.Errorf("bad number")
149149
}
@@ -159,7 +159,7 @@ func TestForEach_IntItems(t *testing.T) {
159159
}
160160

161161
func TestMap_AllSucceed(t *testing.T) {
162-
results, err := Map(context.Background(), []int{1, 2, 3}, func(_ context.Context, _ int, n int) (string, error) {
162+
results, err := Map(t.Context(), []int{1, 2, 3}, func(_ context.Context, _ int, n int) (string, error) {
163163
return fmt.Sprintf("v%d", n), nil
164164
})
165165
if err != nil {
@@ -177,7 +177,7 @@ func TestMap_AllSucceed(t *testing.T) {
177177
}
178178

179179
func TestMap_FailFast(t *testing.T) {
180-
results, err := Map(context.Background(), []int{1, 2, 3}, func(_ context.Context, _ int, n int) (string, error) {
180+
results, err := Map(t.Context(), []int{1, 2, 3}, func(_ context.Context, _ int, n int) (string, error) {
181181
if n == 2 {
182182
return "", fmt.Errorf("fail on %d", n)
183183
}
@@ -193,7 +193,7 @@ func TestMap_FailFast(t *testing.T) {
193193
}
194194

195195
func TestMap_Empty(t *testing.T) {
196-
results, err := Map(context.Background(), []int{}, func(_ context.Context, _ int, _ int) (string, error) {
196+
results, err := Map(t.Context(), []int{}, func(_ context.Context, _ int, _ int) (string, error) {
197197
t.Fatal("should not be called")
198198
return "", nil
199199
})
@@ -206,7 +206,7 @@ func TestMap_Empty(t *testing.T) {
206206
}
207207

208208
func TestMap_PreservesOrder(t *testing.T) {
209-
results, err := Map(context.Background(), []int{10, 20, 30, 40, 50}, func(_ context.Context, _ int, n int) (int, error) {
209+
results, err := Map(t.Context(), []int{10, 20, 30, 40, 50}, func(_ context.Context, _ int, n int) (int, error) {
210210
time.Sleep(time.Duration(50-n) * time.Millisecond) // reverse completion order
211211
return n * 2, nil
212212
})
@@ -225,7 +225,7 @@ func TestMap_WithConcurrencyLimit(t *testing.T) {
225225
var peak atomic.Int32
226226
var cur atomic.Int32
227227

228-
results, err := Map(context.Background(), []int{1, 2, 3, 4, 5}, func(_ context.Context, _ int, n int) (int, error) {
228+
results, err := Map(t.Context(), []int{1, 2, 3, 4, 5}, func(_ context.Context, _ int, n int) (int, error) {
229229
c := cur.Add(1)
230230
for {
231231
old := peak.Load()
@@ -250,7 +250,7 @@ func TestMap_WithConcurrencyLimit(t *testing.T) {
250250

251251
func TestMap_IndexPassedCorrectly(t *testing.T) {
252252
items := []string{"a", "b", "c"}
253-
results, err := Map(context.Background(), items, func(_ context.Context, idx int, item string) (string, error) {
253+
results, err := Map(t.Context(), items, func(_ context.Context, idx int, item string) (string, error) {
254254
return fmt.Sprintf("%d:%s", idx, item), nil
255255
})
256256
if err != nil {

0 commit comments

Comments
 (0)