@@ -2,7 +2,6 @@ package mounter
2
2
3
3
import (
4
4
"errors"
5
- "fmt"
6
5
"os"
7
6
"testing"
8
7
@@ -190,6 +189,8 @@ func TestRcloneMount_WorkerNode_Negative(t *testing.T) {
190
189
func TestRcloneUnmount_NodeServer (t * testing.T ) {
191
190
mountWorker = false
192
191
192
+ removeConfigFile = func (_ , _ string ) {}
193
+
193
194
rclone := & RcloneMounter {MounterUtils : mounterUtils .NewFakeMounterUtilsImpl (mounterUtils.FakeMounterUtilsFuncStruct {
194
195
FuseUnmountFn : func (path string ) error {
195
196
return nil
@@ -203,6 +204,8 @@ func TestRcloneUnmount_NodeServer(t *testing.T) {
203
204
func TestRcloneUnmount_WorkerNode (t * testing.T ) {
204
205
mountWorker = true
205
206
207
+ removeConfigFile = func (_ , _ string ) {}
208
+
206
209
rclone := & RcloneMounter {MounterUtils : mounterUtils .NewFakeMounterUtilsImpl (mounterUtils.FakeMounterUtilsFuncStruct {
207
210
FuseUnmountFn : func (path string ) error {
208
211
return nil
@@ -235,6 +238,22 @@ func TestRcloneUnmount_WorkerNode_Negative(t *testing.T) {
235
238
assert .Contains (t , err .Error (), "failed to create http request" )
236
239
}
237
240
241
+ func TestRcloneUnmount_NodeServer_Negative (t * testing.T ) {
242
+ mountWorker = false
243
+
244
+ removeConfigFile = func (_ , _ string ) {}
245
+
246
+ rclone := & RcloneMounter {MounterUtils : mounterUtils .NewFakeMounterUtilsImpl (mounterUtils.FakeMounterUtilsFuncStruct {
247
+ FuseUnmountFn : func (path string ) error {
248
+ return errors .New ("failed to unmount" )
249
+ },
250
+ })}
251
+
252
+ err := rclone .Unmount (target )
253
+ assert .Error (t , err )
254
+ assert .Contains (t , err .Error (), "failed to unmount" )
255
+ }
256
+
238
257
func TestCreateConfig_Success (t * testing.T ) {
239
258
rclone := & RcloneMounter {
240
259
AccessKeys : "accessKey:secretKey" ,
@@ -247,7 +266,7 @@ func TestCreateConfig_Success(t *testing.T) {
247
266
248
267
func TestCreateConfig_MakeDirFails (t * testing.T ) {
249
268
MakeDir = func (string , os.FileMode ) error {
250
- return fmt . Errorf ("mkdir failed" )
269
+ return errors . New ("mkdir failed" )
251
270
}
252
271
err := createConfig ("/tmp/testconfig" , & RcloneMounter {})
253
272
assert .ErrorContains (t , err , "mkdir failed" )
@@ -256,7 +275,7 @@ func TestCreateConfig_MakeDirFails(t *testing.T) {
256
275
func TestCreateConfig_FileCreateFails (t * testing.T ) {
257
276
MakeDir = func (string , os.FileMode ) error { return nil }
258
277
CreateFile = func (string ) (* os.File , error ) {
259
- return nil , fmt . Errorf ("file create failed" )
278
+ return nil , errors . New ("file create failed" )
260
279
}
261
280
err := createConfig ("/tmp/testconfig" , & RcloneMounter {})
262
281
assert .ErrorContains (t , err , "file create failed" )
@@ -268,8 +287,80 @@ func TestCreateConfig_ChmodFails(t *testing.T) {
268
287
return os .CreateTemp ("" , "test" )
269
288
}
270
289
Chmod = func (string , os.FileMode ) error {
271
- return fmt . Errorf ("chmod failed" )
290
+ return errors . New ("chmod failed" )
272
291
}
273
292
err := createConfig ("/tmp/testconfig" , & RcloneMounter {})
274
293
assert .ErrorContains (t , err , "chmod failed" )
275
294
}
295
+
296
+ func TestRemoveRcloneConfigFile_PathNotExists (t * testing.T ) {
297
+ Stat = func (path string ) (os.FileInfo , error ) {
298
+ return nil , os .ErrNotExist
299
+ }
300
+ defer func () {
301
+ Stat = os .Stat
302
+ }()
303
+
304
+ removeRcloneConfigFile ("/test" , target )
305
+ }
306
+
307
+ func TestRemoveRcloneConfigFile_StatRetryThenSuccess (t * testing.T ) {
308
+ attempt := 0
309
+ Stat = func (_ string ) (os.FileInfo , error ) {
310
+ if attempt == 0 {
311
+ attempt ++
312
+ return nil , errors .New ("stat error" )
313
+ }
314
+ return nil , nil
315
+ }
316
+ defer func () {
317
+ Stat = os .Stat
318
+ }()
319
+
320
+ RemoveAll = func (_ string ) error {
321
+ return nil
322
+ }
323
+
324
+ removeRcloneConfigFile ("/test1" , target )
325
+ }
326
+
327
+ func TestRemoveRcloneConfigFile_RemoveRetryThenSuccess (t * testing.T ) {
328
+ Stat = func (_ string ) (os.FileInfo , error ) {
329
+ return nil , nil
330
+ }
331
+
332
+ attempt := 0
333
+ RemoveAll = func (_ string ) error {
334
+ if attempt == 0 {
335
+ attempt ++
336
+ return errors .New ("remove error" )
337
+ }
338
+ return nil
339
+ }
340
+
341
+ defer func () {
342
+ Stat = os .Stat
343
+ RemoveAll = os .RemoveAll
344
+ }()
345
+
346
+ removeRcloneConfigFile ("/test" , target )
347
+ }
348
+
349
+ func TestRemoveRcloneConfigFile_Negative (t * testing.T ) {
350
+ called := 0
351
+ Stat = func (_ string ) (os.FileInfo , error ) {
352
+ return nil , nil
353
+ }
354
+ RemoveAll = func (_ string ) error {
355
+ called ++
356
+ return errors .New ("remove failed" )
357
+ }
358
+
359
+ defer func () {
360
+ Stat = os .Stat
361
+ RemoveAll = os .RemoveAll
362
+ }()
363
+
364
+ removeRcloneConfigFile ("/test" , target )
365
+ assert .Equal (t , maxRetries , called )
366
+ }
0 commit comments