Skip to content

Commit db86b2a

Browse files
committed
fix: add tests to ensure that Docker mount points are being rewritten properly (#173)
1 parent a27c62b commit db86b2a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pkg/retrieval/engine/postgres/tools/tools_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
"testing"
1111

12+
"github.com/docker/docker/api/types"
13+
"github.com/docker/docker/api/types/mount"
1214
"github.com/stretchr/testify/assert"
1315
"github.com/stretchr/testify/require"
1416
)
@@ -33,3 +35,48 @@ func TestIfDirectoryEmpty(t *testing.T) {
3335
require.NoError(t, err)
3436
assert.False(t, isEmpty)
3537
}
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

Comments
 (0)