9
9
"os"
10
10
"testing"
11
11
12
+ "github.com/docker/docker/api/types"
13
+ "github.com/docker/docker/api/types/mount"
12
14
"github.com/stretchr/testify/assert"
13
15
"github.com/stretchr/testify/require"
14
16
)
@@ -33,3 +35,48 @@ func TestIfDirectoryEmpty(t *testing.T) {
33
35
require .NoError (t , err )
34
36
assert .False (t , isEmpty )
35
37
}
38
+
39
+ func TestGetMountsFromMountPoints (t * testing.T ) {
40
+ testCases := []struct {
41
+ dataDir string
42
+ mountPoints []types.MountPoint
43
+ expectedPoints []mount.Mount
44
+ }{
45
+ {
46
+ dataDir : "/var/lib/dblab/clones/dblab_clone_6000/data" ,
47
+ mountPoints : []types.MountPoint {{
48
+ Source : "/var/lib/pgsql/data" ,
49
+ Destination : "/var/lib/postgresql/data" ,
50
+ }},
51
+ expectedPoints : []mount.Mount {{
52
+ Source : "/var/lib/pgsql/data" ,
53
+ Target : "/var/lib/postgresql/data" ,
54
+ ReadOnly : true ,
55
+ BindOptions : & mount.BindOptions {
56
+ Propagation : "" ,
57
+ },
58
+ }},
59
+ },
60
+
61
+ {
62
+ dataDir : "/var/lib/dblab/clones/dblab_clone_6000/data" ,
63
+ mountPoints : []types.MountPoint {{
64
+ Source : "/var/lib/postgresql" ,
65
+ Destination : "/var/lib/dblab" ,
66
+ }},
67
+ expectedPoints : []mount.Mount {{
68
+ Source : "/var/lib/postgresql/clones/dblab_clone_6000/data" ,
69
+ Target : "/var/lib/dblab/clones/dblab_clone_6000/data" ,
70
+ ReadOnly : true ,
71
+ BindOptions : & mount.BindOptions {
72
+ Propagation : "" ,
73
+ },
74
+ }},
75
+ },
76
+ }
77
+
78
+ for _ , tc := range testCases {
79
+ mounts := GetMountsFromMountPoints (tc .dataDir , tc .mountPoints )
80
+ assert .Equal (t , tc .expectedPoints , mounts )
81
+ }
82
+ }
0 commit comments