@@ -22,16 +22,22 @@ func clearEnv() {
2222 }
2323}
2424
25- func setMinimalEnv () {
25+ func setMinimalEnv (t * testing. T ) {
2626 os .Setenv ("ENGINE" , "pg" )
2727 os .Setenv ("DB_HOST" , "localhost" )
2828 os .Setenv ("DB_NAME" , "testdb" )
2929 os .Setenv ("RCLONE_REMOTE" , "s3:my-bucket/backups" )
30+
31+ // Create temporary rclone config file
32+ dir := t .TempDir ()
33+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
34+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
35+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
3036}
3137
3238func TestLoad_MinimalConfig (t * testing.T ) {
3339 clearEnv ()
34- setMinimalEnv ()
40+ setMinimalEnv (t )
3541
3642 cfg , err := Load ()
3743 if err != nil {
@@ -115,6 +121,12 @@ func TestLoad_DBURI(t *testing.T) {
115121 os .Setenv ("DB_URI" , "mongodb://user:pass@host:27017/mydb" )
116122 os .Setenv ("RCLONE_REMOTE" , "s3:bucket" )
117123
124+ // Create temporary rclone config file
125+ dir := t .TempDir ()
126+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
127+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
128+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
129+
118130 cfg , err := Load ()
119131 if err != nil {
120132 t .Fatalf ("unexpected error: %v" , err )
@@ -132,9 +144,14 @@ func TestLoad_FileVariant(t *testing.T) {
132144 uriFile := filepath .Join (dir , "db_uri.txt" )
133145 os .WriteFile (uriFile , []byte ("postgresql://user:secret@dbhost:5432/prod\n " ), 0o644 )
134146
147+ // Create temporary rclone config file
148+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
149+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
150+
135151 os .Setenv ("ENGINE" , "pg" )
136152 os .Setenv ("DB_URI_FILE" , uriFile )
137153 os .Setenv ("RCLONE_REMOTE" , "s3:bucket" )
154+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
138155
139156 cfg , err := Load ()
140157 if err != nil {
@@ -152,10 +169,15 @@ func TestLoad_FileVariantPrecedence(t *testing.T) {
152169 uriFile := filepath .Join (dir , "db_uri.txt" )
153170 os .WriteFile (uriFile , []byte ("from-file" ), 0o644 )
154171
172+ // Create temporary rclone config file
173+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
174+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
175+
155176 os .Setenv ("ENGINE" , "pg" )
156177 os .Setenv ("DB_URI" , "from-env" )
157178 os .Setenv ("DB_URI_FILE" , uriFile )
158179 os .Setenv ("RCLONE_REMOTE" , "s3:bucket" )
180+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
159181
160182 cfg , err := Load ()
161183 if err != nil {
@@ -174,11 +196,16 @@ func TestLoad_PasswordFile(t *testing.T) {
174196 pwFile := filepath .Join (dir , "password.txt" )
175197 os .WriteFile (pwFile , []byte (" s3cret \n " ), 0o644 )
176198
199+ // Create temporary rclone config file
200+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
201+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
202+
177203 os .Setenv ("ENGINE" , "pg" )
178204 os .Setenv ("DB_HOST" , "localhost" )
179205 os .Setenv ("DB_NAME" , "testdb" )
180206 os .Setenv ("DB_PASSWORD_FILE" , pwFile )
181207 os .Setenv ("RCLONE_REMOTE" , "s3:bucket" )
208+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
182209
183210 cfg , err := Load ()
184211 if err != nil {
@@ -191,7 +218,7 @@ func TestLoad_PasswordFile(t *testing.T) {
191218
192219func TestLoad_ScheduleOnce (t * testing.T ) {
193220 clearEnv ()
194- setMinimalEnv ()
221+ setMinimalEnv (t )
195222 os .Setenv ("BACKUP_SCHEDULE" , "once" )
196223
197224 cfg , err := Load ()
@@ -205,7 +232,7 @@ func TestLoad_ScheduleOnce(t *testing.T) {
205232
206233func TestLoad_ScheduleOnceCaseInsensitive (t * testing.T ) {
207234 clearEnv ()
208- setMinimalEnv ()
235+ setMinimalEnv (t )
209236 os .Setenv ("BACKUP_SCHEDULE" , "Once" )
210237
211238 cfg , err := Load ()
@@ -219,7 +246,7 @@ func TestLoad_ScheduleOnceCaseInsensitive(t *testing.T) {
219246
220247func TestLoad_InvalidSchedule (t * testing.T ) {
221248 clearEnv ()
222- setMinimalEnv ()
249+ setMinimalEnv (t )
223250 os .Setenv ("BACKUP_SCHEDULE" , "invalid-cron" )
224251
225252 _ , err := Load ()
@@ -230,7 +257,7 @@ func TestLoad_InvalidSchedule(t *testing.T) {
230257
231258func TestLoad_InvalidMode (t * testing.T ) {
232259 clearEnv ()
233- setMinimalEnv ()
260+ setMinimalEnv (t )
234261 os .Setenv ("BACKUP_MODE" , "invalid" )
235262
236263 _ , err := Load ()
@@ -241,7 +268,7 @@ func TestLoad_InvalidMode(t *testing.T) {
241268
242269func TestLoad_Timeout (t * testing.T ) {
243270 clearEnv ()
244- setMinimalEnv ()
271+ setMinimalEnv (t )
245272 os .Setenv ("BACKUP_TIMEOUT" , "30m" )
246273
247274 cfg , err := Load ()
@@ -255,7 +282,7 @@ func TestLoad_Timeout(t *testing.T) {
255282
256283func TestLoad_InvalidTimeout (t * testing.T ) {
257284 clearEnv ()
258- setMinimalEnv ()
285+ setMinimalEnv (t )
259286 os .Setenv ("BACKUP_TIMEOUT" , "notaduration" )
260287
261288 _ , err := Load ()
@@ -266,7 +293,7 @@ func TestLoad_InvalidTimeout(t *testing.T) {
266293
267294func TestLoad_InvalidNotifyOn (t * testing.T ) {
268295 clearEnv ()
269- setMinimalEnv ()
296+ setMinimalEnv (t )
270297 os .Setenv ("NOTIFY_ON" , "never" )
271298
272299 _ , err := Load ()
@@ -285,6 +312,12 @@ func TestLoad_AllEngines(t *testing.T) {
285312 os .Setenv ("DB_NAME" , "testdb" )
286313 os .Setenv ("RCLONE_REMOTE" , "s3:bucket" )
287314
315+ // Create temporary rclone config file
316+ dir := t .TempDir ()
317+ rcloneConfigFile := filepath .Join (dir , "rclone.conf" )
318+ os .WriteFile (rcloneConfigFile , []byte ("[s3]\n type = s3\n " ), 0o644 )
319+ os .Setenv ("RCLONE_CONFIG_FILE" , rcloneConfigFile )
320+
288321 cfg , err := Load ()
289322 if err != nil {
290323 t .Fatalf ("unexpected error for engine %s: %v" , eng , err )
@@ -298,7 +331,7 @@ func TestLoad_AllEngines(t *testing.T) {
298331
299332func TestLoad_Defaults (t * testing.T ) {
300333 clearEnv ()
301- setMinimalEnv ()
334+ setMinimalEnv (t )
302335
303336 cfg , err := Load ()
304337 if err != nil {
@@ -314,7 +347,7 @@ func TestLoad_Defaults(t *testing.T) {
314347 {"BackupNameTemplate" , cfg .BackupNameTemplate , "{db}-{date}-{time}" },
315348 {"NotifyOn" , cfg .NotifyOn , "failure" },
316349 {"LogLevel" , cfg .LogLevel , "info" },
317- {"LogFormat" , cfg .LogFormat , "json " },
350+ {"LogFormat" , cfg .LogFormat , "text " },
318351 {"Timezone" , cfg .Timezone , "UTC" },
319352 {"BackupTempDir" , cfg .BackupTempDir , "/tmp/dbstash-work" },
320353 {"DBAuthSource" , cfg .DBAuthSource , "admin" },
0 commit comments