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: 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" 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) })