From 0fe42b517fd008bb65981dedd82bbab5685b409b Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 26 Jul 2025 11:07:20 +0800 Subject: [PATCH] Update S3 storage tests to use UUIDs for file identifiers - Modified test cases in `storage_test.go` to generate unique file IDs using UUIDs, ensuring no conflicts during tests. - Updated the download test for non-existent files to utilize a UUID-based identifier, enhancing test reliability. --- attachment/s3/storage_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/attachment/s3/storage_test.go b/attachment/s3/storage_test.go index 20b066c0..c48fb35b 100644 --- a/attachment/s3/storage_test.go +++ b/attachment/s3/storage_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/stretchr/testify/assert" ) @@ -93,7 +94,7 @@ func TestS3Storage(t *testing.T) { storage, err := New(getS3Config()) assert.NoError(t, err) - fileID := "test-chunked.txt" + fileID := "test-chunked-" + uuid.New().String() + ".txt" content1 := []byte("chunk1") content2 := []byte("chunk2") @@ -128,7 +129,7 @@ func TestS3Storage(t *testing.T) { storage, err := New(getS3Config()) assert.NoError(t, err) - fileID := "test-ops.txt" + fileID := "test-ops-" + uuid.New().String() + ".txt" content := []byte("test content") // Upload file @@ -163,7 +164,9 @@ func TestS3Storage(t *testing.T) { storage, err := New(getS3Config()) assert.NoError(t, err) - _, _, err = storage.Download(context.Background(), "non-existent.txt") + // Use UUID for non-existent file to avoid any potential conflicts + nonExistentFileID := "non-existent-" + uuid.New().String() + ".txt" + _, _, err = storage.Download(context.Background(), nonExistentFileID) assert.Error(t, err) })