Skip to content

Commit

Permalink
fix: use map for key and values
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikozyurtt committed Jul 11, 2024
1 parent fd902a9 commit 6d59a16
Showing 1 changed file with 50 additions and 36 deletions.
86 changes: 50 additions & 36 deletions e2e/cat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func TestCatS3Object(t *testing.T) {
assertLines(t, result.Stdout(), tc.expected)
})
}

}

func TestCatS3ObjectFail(t *testing.T) {
Expand Down Expand Up @@ -274,7 +273,7 @@ func TestCatByVersionID(t *testing.T) {

const filename = "testfile.txt"

var contents = []string{
contents := []string{
"This is first content",
"Second content it is, and it is a bit longer!!!",
}
Expand Down Expand Up @@ -355,52 +354,71 @@ func TestCatPrefix(t *testing.T) {
t.Parallel()

testCases := []struct {
files []string
contents []string
prefix string
expected string
filesAndContents map[string]string
prefix string
expected string
}{
{
files: []string{"file1.txt", "file2.txt"},
contents: []string{"content0", "content1"},
expected: "content0content1"},
filesAndContents: map[string]string{
"file1.txt": "content0",
"file2.txt": "content1",
},
expected: "content0content1",
},
{
files: []string{"file1.txt", "file2.txt", "dir/file3.txt", "dir/file4.txt"},
contents: []string{"content0", "content1", "content2", "content3"},
filesAndContents: map[string]string{
"file1.txt": "content0",
"file2.txt": "content1",
"dir/file3.txt": "content2",
"dir/file4.txt": "content3",
},
expected: "content0content1",
},
{
files: []string{"file1.txt", "file2.txt", "dir/file3.txt", "dir/file4.txt"},
contents: []string{"content0", "content1", "content2", "content3"},
filesAndContents: map[string]string{
"file1.txt": "content0",
"file2.txt": "content1",
"dir/file3.txt": "content2",
"dir/file4.txt": "content3",
},
prefix: "dir/",
expected: "content2content3",
},
{
files: []string{"file1.txt", "file2.txt", "dir/file3.txt", "dir/file4.txt", "dir/nesteddir/file5.txt"},
contents: []string{"content0", "content1", "content2", "content3", "content4"},
filesAndContents: map[string]string{
"file1.txt": "content0",
"file2.txt": "content1",
"dir/file3.txt": "content2",
"dir/file4.txt": "content3",
"dir/nesteddir/file5.txt": "content4",
},
prefix: "dir/",
expected: "content2content3",
},
{
files: []string{"file1.txt", "file2.txt", "dir/file3.txt", "dir/file4.txt", "dir/nesteddir/file5.txt"},
contents: []string{"content0", "content1", "content2", "content3", "content4"},
filesAndContents: map[string]string{
"file1.txt": "content0",
"file2.txt": "content1",
"dir/file3.txt": "content2",
"dir/file4.txt": "content3",
"dir/nesteddir/file5.txt": "content4",
},
prefix: "dir/nesteddir/",
expected: "content4",
},
}

for _, tc := range testCases {
for idx, tc := range testCases {
tc := tc
t.Run(tc.expected, func(t *testing.T) {
t.Run(fmt.Sprintf("case-%v", idx), func(t *testing.T) {
t.Parallel()

s3client, s5cmd := setup(t)

bucket := s3BucketFromTestName(t)
createBucket(t, s3client, bucket)

for idx, file := range tc.files {
content := tc.contents[idx]
for file, content := range tc.filesAndContents {
putFile(t, s3client, bucket, file, content)
}

Expand All @@ -422,22 +440,19 @@ func TestCatWildcard(t *testing.T) {
bucket := s3BucketFromTestName(t)
createBucket(t, s3client, bucket)

files := []struct {
key string
content string
}{
{"foo1.txt", "content0"},
{"foo2.txt", "content1"},
{"bar1.txt", "content2"},
{"foolder/foo3.txt", "content3"},
{"log-file-2024-01.txt", "content4"},
{"log-file-2024-02.txt", "content5"},
{"log-file-2023-01.txt", "content6"},
{"log-file-2022-01.txt", "content7"},
fileAndContent := map[string]string{
"foo1.txt": "content0",
"foo2.txt": "content1",
"bar1.txt": "content2",
"foolder/foo3.txt": "content3",
"log-file-2024-01.txt": "content4",
"log-file-2024-02.txt": "content5",
"log-file-2023-01.txt": "content6",
"log-file-2022-01.txt": "content7",
}

for _, file := range files {
putFile(t, s3client, bucket, file.key, file.content)
for file, content := range fileAndContent {
putFile(t, s3client, bucket, file, content)
}

testCases := []struct {
Expand Down Expand Up @@ -532,5 +547,4 @@ func TestPrefixWildcardFail(t *testing.T) {
})
})
}

}

0 comments on commit 6d59a16

Please sign in to comment.