Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FEATURE (s3): Test connection via uploading\removing test file

Rostislav Duginf9eaead8a101
diff --git a/backend/Makefile b/backend/Makefile
index 435ed021..cf5535d8 100644
--- a/backend/Makefile
+++ b/backend/Makefile
@@ -2,7 +2,7 @@ run:
go run cmd/main.go
test:
- go test -count=1 ./internal/...
+ go test -p=1 -count=1 -failfast .\internal\...
lint:
golangci-lint fmt && golangci-lint run
diff --git a/backend/internal/features/storages/models/s3/model.go b/backend/internal/features/storages/models/s3/model.go
index d94c7042..b1e6b9ba 100644
--- a/backend/internal/features/storages/models/s3/model.go
+++ b/backend/internal/features/storages/models/s3/model.go
@@ -1,6 +1,7 @@
package s3_storage
import (
+ "bytes"
"context"
"errors"
"fmt"
@@ -129,7 +130,7 @@ func (s *S3Storage) TestConnection() error {
return err
}
- // Create a context with 5 second timeout
+ // Create a context with 10 second timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
@@ -147,6 +148,35 @@ func (s *S3Storage) TestConnection() error {
return fmt.Errorf("bucket '%s' does not exist", s.S3Bucket)
}
+ // Test write and delete permissions by uploading and removing a small test file
+ testFileID := uuid.New().String() + "-test"
+ testData := []byte("test connection")
+ testReader := bytes.NewReader(testData)
+
+ // Upload test file
+ _, err = client.PutObject(
+ ctx,
+ s.S3Bucket,
+ testFileID,
+ testReader,
+ int64(len(testData)),
+ minio.PutObjectOptions{},
+ )
+ if err != nil {
+ return fmt.Errorf("failed to upload test file to S3: %w", err)
+ }
+
+ // Delete test file
+ err = client.RemoveObject(
+ ctx,
+ s.S3Bucket,
+ testFileID,
+ minio.RemoveObjectOptions{},
+ )
+ if err != nil {
+ return fmt.Errorf("failed to delete test file from S3: %w", err)
+ }
+
return nil
}