-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete_file_test.go
120 lines (89 loc) · 3.42 KB
/
delete_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package mtpx
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"log"
"math/rand"
"testing"
)
func TestDeleteFile(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("Delete an existing object | using objectId | DeleteFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-DeleteFile/{random}'
directoryName := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
objectId, err := MakeDirectory(dev, sid, directoryName)
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{{objectId, ""}})
So(err, ShouldBeNil)
})
Convey("Delete multiple existing objects | using objectId | DeleteFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-DeleteFile/{random}'
directoryName1 := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
directoryName2 := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
objectId1, err := MakeDirectory(dev, sid, directoryName1)
So(err, ShouldBeNil)
objectId2, err := MakeDirectory(dev, sid, directoryName2)
So(err, ShouldBeNil)
So(objectId1, ShouldBeGreaterThan, 0)
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{
{objectId1, ""},
{objectId2, ""},
})
So(err, ShouldBeNil)
})
Convey("Delete an existing object | using fullPath | DeleteFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-DeleteFile/{random}'
directoryName := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
objectId, err := MakeDirectory(dev, sid, directoryName)
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{{0, directoryName}})
So(err, ShouldBeNil)
})
Convey("Delete multiple existing objects | using fullPath | DeleteFile", t, func() {
// create a random directory
// test the directory '/mtp-test-files/temp_dir/test-DeleteFile/{random}'
directoryName1 := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
directoryName2 := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
objectId1, err := MakeDirectory(dev, sid, directoryName1)
So(err, ShouldBeNil)
objectId2, err := MakeDirectory(dev, sid, directoryName2)
So(err, ShouldBeNil)
So(objectId1, ShouldBeGreaterThan, 0)
So(objectId2, ShouldBeGreaterThan, 0)
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{
{0, directoryName1},
{0, directoryName2},
})
So(err, ShouldBeNil)
})
Convey("Delete an non existing object | using objectId | DeleteFile", t, func() {
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{{1234567, ""}})
So(err, ShouldBeNil)
})
Convey("Delete an non existing object | using fullPath | DeleteFile", t, func() {
// test the directory '/mtp-test-files/temp_dir/test-DeleteFile/{random}'
directoryName := fmt.Sprintf("/mtp-test-files/temp_dir/test-DeleteFile/%x", rand.Int31())
//delete the object using objectId
err = DeleteFile(dev, sid, []FileProp{{0, directoryName}})
So(err, ShouldBeNil)
})
Dispose(dev)
}