@@ -37,11 +37,13 @@ func TestIfDirectoryEmpty(t *testing.T) {
3737
3838func TestGetMountsFromMountPoints (t * testing.T ) {
3939 testCases := []struct {
40+ name string
4041 dataDir string
4142 mountPoints []types.MountPoint
4243 expectedPoints []mount.Mount
4344 }{
4445 {
46+ name : "simple mount without transformation" ,
4547 dataDir : "/var/lib/dblab/clones/dblab_clone_6000/data" ,
4648 mountPoints : []types.MountPoint {{
4749 Source : "/var/lib/pgsql/data" ,
@@ -56,8 +58,8 @@ func TestGetMountsFromMountPoints(t *testing.T) {
5658 },
5759 }},
5860 },
59-
6061 {
62+ name : "mount with path transformation" ,
6163 dataDir : "/var/lib/dblab/clones/dblab_clone_6000/data" ,
6264 mountPoints : []types.MountPoint {{
6365 Source : "/var/lib/postgresql" ,
@@ -72,10 +74,44 @@ func TestGetMountsFromMountPoints(t *testing.T) {
7274 },
7375 }},
7476 },
77+ {
78+ name : "deduplicate identical mounts" ,
79+ dataDir : "/var/lib/dblab/data" ,
80+ mountPoints : []types.MountPoint {
81+ {Source : "/host/dump" , Destination : "/var/lib/dblab/dump" },
82+ {Source : "/host/dump" , Destination : "/var/lib/dblab/dump" },
83+ },
84+ expectedPoints : []mount.Mount {{
85+ Source : "/host/dump" ,
86+ Target : "/var/lib/dblab/dump" ,
87+ ReadOnly : true ,
88+ BindOptions : & mount.BindOptions {
89+ Propagation : "" ,
90+ },
91+ }},
92+ },
93+ {
94+ name : "deduplicate mounts with trailing slashes" ,
95+ dataDir : "/var/lib/dblab/data" ,
96+ mountPoints : []types.MountPoint {
97+ {Source : "/host/dump/" , Destination : "/var/lib/dblab/dump" },
98+ {Source : "/host/dump" , Destination : "/var/lib/dblab/dump/" },
99+ },
100+ expectedPoints : []mount.Mount {{
101+ Source : "/host/dump/" ,
102+ Target : "/var/lib/dblab/dump" ,
103+ ReadOnly : true ,
104+ BindOptions : & mount.BindOptions {
105+ Propagation : "" ,
106+ },
107+ }},
108+ },
75109 }
76110
77111 for _ , tc := range testCases {
78- mounts := GetMountsFromMountPoints (tc .dataDir , tc .mountPoints )
79- assert .Equal (t , tc .expectedPoints , mounts )
112+ t .Run (tc .name , func (t * testing.T ) {
113+ mounts := GetMountsFromMountPoints (tc .dataDir , tc .mountPoints )
114+ assert .Equal (t , tc .expectedPoints , mounts )
115+ })
80116 }
81117}
0 commit comments