-
Notifications
You must be signed in to change notification settings - Fork 6
/
make_directory_test.go
96 lines (73 loc) · 2.58 KB
/
make_directory_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
package mtpx
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"log"
"math/rand"
"testing"
)
func TestMakeDirectory(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
var _objectId uint32
Convey("Creating a new dir | MakeDirectory", t, func() {
// test the directory '/mtp-test-files/temp_dir/test-MakeDirectory'
objectId, err := MakeDirectory(dev, sid, "/mtp-test-files/temp_dir/test-MakeDirectory")
_objectId = objectId
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
})
Convey("Testing MakeDirectory for an existing directory | MakeDirectory", t, func() {
// test the directory '/mtp-test-files/temp_dir/test-MakeDirectory'
objectId, err := MakeDirectory(dev, sid, "/mtp-test-files/temp_dir/test-MakeDirectory")
So(err, ShouldBeNil)
So(objectId, ShouldEqual, _objectId)
})
Convey("Testing fullpath='/' | MakeDirectory", t, func() {
// test the directory '/'
objectId, err := MakeDirectory(dev, sid, "/")
So(err, ShouldBeNil)
So(objectId, ShouldEqual, ParentObjectId)
})
Convey("Testing fullpath='' | MakeDirectory", t, func() {
// test the directory ''
objectId, err := MakeDirectory(dev, sid, "")
So(err, ShouldBeNil)
So(objectId, ShouldEqual, ParentObjectId)
})
Convey("Creating a new random dir | MakeDirectory", t, func() {
// test the directory '/mtp-test-files/temp_dir/test-MakeDirectory/{random}'
fullpath := fmt.Sprintf("/mtp-test-files/temp_dir/test-MakeDirectory/%x", rand.Int31())
objectId, err := MakeDirectory(dev, sid, fullpath)
So(err, ShouldBeNil)
So(objectId, ShouldBeGreaterThan, 0)
fc, err := FileExists(dev, sid, []FileProp{{0, fullpath}})
So(err, ShouldBeNil)
fi := fc[0].FileInfo
So(fc[0].Exists, ShouldEqual, true)
So(fi.ObjectId, ShouldEqual, objectId)
So(fi.IsDir, ShouldEqual, true)
})
Convey("filename in the path | 1 | MakeDirectory | It should throw an error", t, func() {
// test the directory '/mtp-test-files/a.txt/folder'
objectId, err := MakeDirectory(dev, sid, "/mtp-test-files/a.txt/folder")
So(err, ShouldBeError)
So(objectId, ShouldEqual, 0)
So(err, ShouldHaveSameTypeAs, InvalidPathError{})
})
Convey("filename in the path | 2 | MakeDirectory | It should throw an error", t, func() {
// test the directory '/mtp-test-files/a.txt/folder'
objectId, err := MakeDirectory(dev, sid, "/mtp-test-files/a.txt")
So(err, ShouldBeError)
So(objectId, ShouldEqual, 0)
So(err, ShouldHaveSameTypeAs, InvalidPathError{})
})
Dispose(dev)
}