Skip to content

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

FIX (tests): Return ensuring directories for LocalStorage to not fail tests

Rostislav Dugine6ce32bb6004
diff --git a/backend/internal/features/storages/model_test.go b/backend/internal/features/storages/model_test.go
index 3455daa2..40b4a32b 100644
--- a/backend/internal/features/storages/model_test.go
+++ b/backend/internal/features/storages/model_test.go
@@ -12,7 +12,6 @@ import (
local_storage "postgresus-backend/internal/features/storages/models/local"
nas_storage "postgresus-backend/internal/features/storages/models/nas"
s3_storage "postgresus-backend/internal/features/storages/models/s3"
- files_utils "postgresus-backend/internal/util/files"
"postgresus-backend/internal/util/logger"
"strconv"
"testing"
@@ -38,13 +37,6 @@ func Test_Storage_BasicOperations(t *testing.T) {
validateEnvVariables(t)
- // create directories that used for backups and restore
- err := files_utils.EnsureDirectories([]string{
- config.GetEnv().TempFolder,
- config.GetEnv().DataFolder,
- })
- require.NoError(t, err, "Failed to ensure directories")
-
// Setup S3 connection to docker-compose MinIO
s3Container, err := setupS3Container(ctx)
require.NoError(t, err, "Failed to setup S3 container")
diff --git a/backend/internal/features/storages/models/local/model.go b/backend/internal/features/storages/models/local/model.go
index f92ea7ea..dea528ce 100644
--- a/backend/internal/features/storages/models/local/model.go
+++ b/backend/internal/features/storages/models/local/model.go
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"postgresus-backend/internal/config"
+ files_utils "postgresus-backend/internal/util/files"
"github.com/google/uuid"
)
@@ -129,11 +130,18 @@ func (l *LocalStorage) DeleteFile(fileID uuid.UUID) error {
}
func (l *LocalStorage) Validate() error {
- // nothing to validate
return nil
}
func (l *LocalStorage) TestConnection() error {
+ err := files_utils.EnsureDirectories([]string{
+ config.GetEnv().TempFolder,
+ config.GetEnv().DataFolder,
+ })
+ if err != nil {
+ return fmt.Errorf("failed to ensure directories: %w", err)
+ }
+
testFile := filepath.Join(config.GetEnv().TempFolder, "test_connection")
f, err := os.Create(testFile)
if err != nil {