-
Notifications
You must be signed in to change notification settings - Fork 5
/
rename_file_test.go
92 lines (69 loc) · 2.77 KB
/
rename_file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package mtpx
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"log"
"math/rand"
"testing"
"time"
)
func TestRenameFile(t *testing.T) {
dev, err := Initialize(Init{})
if err != nil {
log.Panic(err)
}
storages, err := FetchStorages(dev)
if err != nil {
log.Panic(err)
}
sid := storages[0].Sid
Convey("Rename an existing object | using objectId | RenameFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-RenameFile/{random}'
fileName := fmt.Sprintf("/mtp-test-files/temp_dir/test-RenameFile/%x", rand.Int31())
renameRandFileName := fmt.Sprintf("renamed-%x", rand.Int31())
objectId, err := MakeDirectory(dev, sid, fileName)
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
//rename the object using objectId
objId, err := RenameFile(dev, sid, FileProp{objectId, ""}, renameRandFileName)
So(err, ShouldBeNil)
So(objId, ShouldEqual, objectId)
//try renaming the object using using the same [newFileName]
objId, err = RenameFile(dev, sid, FileProp{objectId, ""}, renameRandFileName)
So(err, ShouldBeNil)
So(objId, ShouldEqual, objectId)
})
Convey("Rename an existing object | using fullPath | RenameFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-RenameFile/{random}'
fileName := fmt.Sprintf("/mtp-test-files/temp_dir/test-RenameFile/%x", rand.Int31())
renameRandFileName := fmt.Sprintf("renamed-%x", rand.Int31())
objectId, err := MakeDirectory(dev, sid, fileName)
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
//rename the object using objectId
objId, err := RenameFile(dev, sid, FileProp{0, fileName}, renameRandFileName)
So(err, ShouldBeNil)
So(objId, ShouldEqual, objectId)
time.Sleep(10000)
//try renaming the object using using the same [newFileName]
objId, err = RenameFile(dev, sid, FileProp{0, getFullPath("/mtp-test-files/temp_dir/test-RenameFile/", renameRandFileName)}, renameRandFileName)
So(err, ShouldBeNil)
So(objId, ShouldEqual, objectId)
})
Convey("Rename an non existing object | using objectId | RenameFile | Should throw an error", t, func() {
//rename the object using objectId
objId, err := RenameFile(dev, sid, FileProp{1234567, ""}, "fake name")
So(err, ShouldHaveSameTypeAs, InvalidPathError{})
So(objId, ShouldEqual, 0)
})
Convey("Rename an non existing object | using fullPath | RenameFile | Should throw an error", t, func() {
// test the directory '/mtp-test-files/temp_dir/test-RenameFile/{random}'
fileName := fmt.Sprintf("/mtp-test-files/temp_dir/test-RenameFile/%x", rand.Int31())
objId, err := RenameFile(dev, sid, FileProp{0, fileName}, "fake name")
So(err, ShouldHaveSameTypeAs, InvalidPathError{})
So(objId, ShouldEqual, 0)
})
Dispose(dev)
}