Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol committed Jul 16, 2024
1 parent 87cf719 commit e2d26dd
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions core/amazon/awssdk/listobjects_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import (
)

func TestListObjects(t *testing.T) {
// Create a temporary directory for testing
// Create a temporary directory and file for testing
tempDir := "test-upload"
err := os.Mkdir(tempDir, 0777)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)

// Create test files and directories
err = os.MkdirAll(filepath.Join(tempDir, "dir1"), os.ModePerm)
if err != nil {
t.Fatal(err)
Expand All @@ -33,28 +32,23 @@ func TestListObjects(t *testing.T) {
t.Fatal(err)
}

// Call the ListObjects function
items, err := ListObjects(filepath.Join(tempDir), "test-upload")
// actual
actualItems, err := ListObjects(filepath.Join(tempDir), "test-upload")
if err != nil {
t.Fatalf("ListObjects returned an error: %v", err)
}

// Define expected results
// expected
expectedItems := []Item{
{Key: "dir1/file2.txt", Size: int64(len("file2 content"))},
{Key: "file1.txt", Size: int64(len("file1 content"))},
}

// Check the number of items
if len(items) != len(expectedItems) {
t.Fatalf("Expected %d items, got %d", len(expectedItems), len(items))
}

// Check each item
for i, item := range items {
if item.Key != expectedItems[i].Key || item.Size != expectedItems[i].Size {
t.Errorf("Expected item %v, got %v", expectedItems[i], item)
}
// assertion
assert.Equal(t, len(actualItems), len(expectedItems))
for i, item := range actualItems {
assert.Equal(t, item.Key, expectedItems[i].Key)
assert.Equal(t, item.Size, expectedItems[i].Size)
}
}

Expand Down

0 comments on commit e2d26dd

Please sign in to comment.