forked from beyondstorage/go-integration-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
direr.go
117 lines (94 loc) · 2.69 KB
/
direr.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
package tests
import (
"testing"
"github.com/google/uuid"
. "github.com/smartystreets/goconvey/convey"
"github.com/beyondstorage/go-storage/v4/pairs"
"github.com/beyondstorage/go-storage/v4/types"
)
func TestDirer(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
d, ok := store.(types.Direr)
So(ok, ShouldBeTrue)
Convey("When CreateDir", func() {
path := uuid.New().String()
o, err := d.CreateDir(path)
defer func() {
err := store.Delete(path, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()
Convey("The first returned error should be nil", func() {
So(err, ShouldBeNil)
})
o, err = d.CreateDir(path)
Convey("The second returned error also should be nil", func() {
So(err, ShouldBeNil)
})
Convey("The Object Path should equal to the input path", func() {
So(o.Path, ShouldEqual, path)
})
Convey("The Object Mode should be dir", func() {
// Dir object's mode must be Dir.
So(o.Mode.IsDir(), ShouldBeTrue)
})
})
Convey("When Create with ModeDir", func() {
path := uuid.New().String()
o := store.Create(path, pairs.WithObjectMode(types.ModeDir))
defer func() {
err := store.Delete(path, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()
Convey("The Object Path should equal to the input path", func() {
So(o.Path, ShouldEqual, path)
})
Convey("The Object Mode should be dir", func() {
// Dir object's mode must be Dir.
So(o.Mode.IsDir(), ShouldBeTrue)
})
})
Convey("When Stat with ModeDir", func() {
path := uuid.New().String()
_, err := d.CreateDir(path)
if err != nil {
t.Error(err)
}
defer func() {
err := store.Delete(path, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()
o, err := store.Stat(path, pairs.WithObjectMode(types.ModeDir))
Convey("The error should be nil", func() {
So(err, ShouldBeNil)
})
Convey("The Object Path should equal to the input path", func() {
So(o.Path, ShouldEqual, path)
})
Convey("The Object Mode should be dir", func() {
// Dir object's mode must be Dir.
So(o.Mode.IsDir(), ShouldBeTrue)
})
})
Convey("When Delete with ModeDir", func() {
path := uuid.New().String()
_, err := d.CreateDir(path)
if err != nil {
t.Error(err)
}
err = store.Delete(path, pairs.WithObjectMode(types.ModeDir))
Convey("The first returned error should be nil", func() {
So(err, ShouldBeNil)
})
err = store.Delete(path, pairs.WithObjectMode(types.ModeDir))
Convey("The second returned error also should be nil", func() {
So(err, ShouldBeNil)
})
})
})
}