diff --git a/registry/storage/driver/s3-aws/s3_test.go b/registry/storage/driver/s3-aws/s3_test.go index cb4240cd0..768497635 100644 --- a/registry/storage/driver/s3-aws/s3_test.go +++ b/registry/storage/driver/s3-aws/s3_test.go @@ -524,6 +524,8 @@ func TestWalk(t *testing.T) { fileset := []string{ "/file1", + "/folder1-suffix", + "/folder1-suffix/file1", "/folder1/file1", "/folder2/file1", "/folder3/subfolder1/subfolder1/file1", @@ -557,6 +559,8 @@ func TestWalk(t *testing.T) { } }() + noopFn := func(fileInfo storagedriver.FileInfo) error { return nil } + tcs := []struct { name string fn storagedriver.WalkFn @@ -567,9 +571,11 @@ func TestWalk(t *testing.T) { }{ { name: "walk all", - fn: func(fileInfo storagedriver.FileInfo) error { return nil }, + fn: noopFn, expected: []string{ "/file1", + "/folder1-suffix", + "/folder1-suffix/file1", "/folder1", "/folder1/file1", "/folder2", @@ -598,6 +604,8 @@ func TestWalk(t *testing.T) { }, expected: []string{ "/file1", + "/folder1-suffix", + "/folder1-suffix/file1", "/folder1", "/folder1/file1", "/folder2", @@ -608,25 +616,9 @@ func TestWalk(t *testing.T) { "/folder4/file1", }, }, - { - name: "stop early", - fn: func(fileInfo storagedriver.FileInfo) error { - if fileInfo.Path() == "/folder1/file1" { - return storagedriver.ErrFilledBuffer - } - return nil - }, - expected: []string{ - "/file1", - "/folder1", - "/folder1/file1", - // stop early - }, - err: false, - }, { name: "start late without from", - fn: func(fileInfo storagedriver.FileInfo) error { return nil }, + fn: noopFn, options: []func(*storagedriver.WalkOptions){ storagedriver.WithStartAfterHint("/folder3/subfolder1/subfolder1/file1"), }, @@ -643,7 +635,7 @@ func TestWalk(t *testing.T) { }, { name: "start late with from", - fn: func(fileInfo storagedriver.FileInfo) error { return nil }, + fn: noopFn, from: "/folder3", options: []func(*storagedriver.WalkOptions){ storagedriver.WithStartAfterHint("/folder3/subfolder1/subfolder1/file1"), @@ -656,6 +648,69 @@ func TestWalk(t *testing.T) { }, err: false, }, + { + name: "start after from", + fn: noopFn, + from: "/folder1", + options: []func(*storagedriver.WalkOptions){ + storagedriver.WithStartAfterHint("/folder1-suffix"), + }, + expected: []string{}, + err: false, + }, + { + name: "start matches from", + fn: noopFn, + from: "/folder3", + options: []func(*storagedriver.WalkOptions){ + storagedriver.WithStartAfterHint("/folder3"), + }, + expected: []string{ + "/folder3/subfolder1", + "/folder3/subfolder1/subfolder1", + "/folder3/subfolder1/subfolder1/file1", + "/folder3/subfolder2", + "/folder3/subfolder2/subfolder1", + "/folder3/subfolder2/subfolder1/file1", + }, + err: false, + }, + { + name: "start doesn't exist", + fn: noopFn, + from: "/folder3", + options: []func(*storagedriver.WalkOptions){ + storagedriver.WithStartAfterHint("/folder3/notafolder/notafile"), + }, + expected: []string{ + "/folder3/subfolder1", + "/folder3/subfolder1/subfolder1", + "/folder3/subfolder1/subfolder1/file1", + "/folder3/subfolder2", + "/folder3/subfolder2/subfolder1", + "/folder3/subfolder2/subfolder1/file1", + }, + err: false, + }, + { + name: "stop early", + fn: func(fileInfo storagedriver.FileInfo) error { + if fileInfo.Path() == "/folder1/file1" { + return storagedriver.ErrFilledBuffer + } + return nil + }, + expected: []string{ + "/file1", + "/folder1-suffix", + "/folder1-suffix/file1", + "/folder1", + "/folder1/file1", + // stop early + }, + err: false, + }, + { name: "error", fn: func(fileInfo storagedriver.FileInfo) error { @@ -668,7 +723,7 @@ func TestWalk(t *testing.T) { }, { name: "from folder", - fn: func(fileInfo storagedriver.FileInfo) error { return nil }, + fn: noopFn, expected: []string{ "/folder1/file1", },