From 18547852b7e30ecc3ef08a0a3cc46d364bde1edb Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Jul 2025 19:05:42 +0800 Subject: [PATCH 1/3] Update S3 configuration in CI workflows - Replaced the S3_CACHE_PATH variable with S3_PUBLIC_URL in both `pr-test.yml` and `unit-test.yml` workflows, enhancing the integration with S3 by providing a public URL for access. - This change aligns with the ongoing improvements to S3-related environment variables for better deployment and testing processes. --- .github/workflows/pr-test.yml | 2 +- .github/workflows/unit-test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 2e961fbc..de6a3c19 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -78,7 +78,7 @@ env: S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_CACHE_PATH: /tmp/s3-cache + S3_PUBLIC_URL: ${{ secrets.S3_PUBLIC_URL }} jobs: UnitTest: diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 833600b0..1cd20423 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -82,7 +82,7 @@ env: S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} S3_BUCKET: ${{ secrets.S3_BUCKET }} - S3_CACHE_PATH: /tmp/s3-cache + S3_PUBLIC_URL: ${{ secrets.S3_PUBLIC_URL }} jobs: unit-test: From 5d5d0d4ce95ee6df23ea09f48370902d7bee7438 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Jul 2025 19:15:18 +0800 Subject: [PATCH 2/3] Improve error messages in S3 storage operations - Enhanced error handling in the S3 storage implementation by including the fileID in error messages for upload, upload chunk, merge chunks, and download operations. This change provides clearer context for debugging and improves the overall error reporting mechanism. --- attachment/s3/storage.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/attachment/s3/storage.go b/attachment/s3/storage.go index 83b6f637..49b7a935 100644 --- a/attachment/s3/storage.go +++ b/attachment/s3/storage.go @@ -122,7 +122,7 @@ func (storage *Storage) Upload(ctx context.Context, fileID string, reader io.Rea ContentType: aws.String(contentType), }) if err != nil { - return "", fmt.Errorf("failed to upload file: %w", err) + return "", fmt.Errorf("failed to upload file %s: %w", fileID, err) } return fileID, nil @@ -144,7 +144,7 @@ func (storage *Storage) UploadChunk(ctx context.Context, fileID string, chunkInd ContentType: aws.String(contentType), }) if err != nil { - return fmt.Errorf("failed to upload chunk %d: %w", chunkIndex, err) + return fmt.Errorf("failed to upload chunk %s %d: %w", fileID, chunkIndex, err) } return nil @@ -182,7 +182,7 @@ func (storage *Storage) MergeChunks(ctx context.Context, fileID string, totalChu _, err = io.Copy(&mergedContent, result.Body) result.Body.Close() if err != nil { - return fmt.Errorf("failed to copy chunk %d: %w", i, err) + return fmt.Errorf("failed to copy chunk %s %d: %w", fileID, i, err) } } @@ -199,7 +199,7 @@ func (storage *Storage) MergeChunks(ctx context.Context, fileID string, totalChu ContentType: aws.String(contentType), }) if err != nil { - return fmt.Errorf("failed to upload merged file: %w", err) + return fmt.Errorf("failed to upload merged file %s: %w", fileID, err) } // Clean up chunks @@ -227,7 +227,7 @@ func (storage *Storage) Reader(ctx context.Context, fileID string) (io.ReadClose Key: aws.String(key), }) if err != nil { - return nil, fmt.Errorf("failed to get file: %w", err) + return nil, fmt.Errorf("failed to get file %s: %w", fileID, err) } // If the file is a gzip file, decompress it @@ -256,7 +256,7 @@ func (storage *Storage) Download(ctx context.Context, fileID string) (io.ReadClo Key: aws.String(key), }) if err != nil { - return nil, "", fmt.Errorf("failed to download file: %w", err) + return nil, "", fmt.Errorf("failed to download file %s: %w", fileID, err) } contentType := "application/octet-stream" From 0fe42b517fd008bb65981dedd82bbab5685b409b Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 26 Jul 2025 11:07:20 +0800 Subject: [PATCH 3/3] 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) })