Skip to content

Commit f9eaead

Browse files
FEATURE (s3): Test connection via uploading\removing test file
1 parent aad9ed6 commit f9eaead

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ run:
22
go run cmd/main.go
33

44
test:
5-
go test -count=1 ./internal/...
5+
go test -p=1 -count=1 -failfast .\internal\...
66

77
lint:
88
golangci-lint fmt && golangci-lint run

backend/internal/features/storages/models/s3/model.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package s3_storage
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
@@ -129,7 +130,7 @@ func (s *S3Storage) TestConnection() error {
129130
return err
130131
}
131132

132-
// Create a context with 5 second timeout
133+
// Create a context with 10 second timeout
133134
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
134135
defer cancel()
135136

@@ -147,6 +148,35 @@ func (s *S3Storage) TestConnection() error {
147148
return fmt.Errorf("bucket '%s' does not exist", s.S3Bucket)
148149
}
149150

151+
// Test write and delete permissions by uploading and removing a small test file
152+
testFileID := uuid.New().String() + "-test"
153+
testData := []byte("test connection")
154+
testReader := bytes.NewReader(testData)
155+
156+
// Upload test file
157+
_, err = client.PutObject(
158+
ctx,
159+
s.S3Bucket,
160+
testFileID,
161+
testReader,
162+
int64(len(testData)),
163+
minio.PutObjectOptions{},
164+
)
165+
if err != nil {
166+
return fmt.Errorf("failed to upload test file to S3: %w", err)
167+
}
168+
169+
// Delete test file
170+
err = client.RemoveObject(
171+
ctx,
172+
s.S3Bucket,
173+
testFileID,
174+
minio.RemoveObjectOptions{},
175+
)
176+
if err != nil {
177+
return fmt.Errorf("failed to delete test file from S3: %w", err)
178+
}
179+
150180
return nil
151181
}
152182

0 commit comments

Comments
 (0)