strip-volatile-option-tmp-mounts

Signed-off-by: krglosse <krglosse@us.ibm.com>

do not alter original slice

Signed-off-by: krglosse <krglosse@us.ibm.com>

Update core/mount/temp.go

makes sense, thank you!

Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: KodieGlosserIBM <39170759+KodieGlosserIBM@users.noreply.github.com>

do not copy mount structure unless conditional is met and adding a test case for it

Signed-off-by: krglosse <krglosse@us.ibm.com>

copy option slice when removing the element instead of giving the element an empty string

remove unneeded block

Signed-off-by: krglosse <krglosse@us.ibm.com>

simplify

Signed-off-by: krglosse <krglosse@us.ibm.com>
This commit is contained in:
krglosse
2024-01-10 12:43:32 -06:00
parent 02e0fef84b
commit cfe8321b4c
2 changed files with 150 additions and 1 deletions

View File

@@ -148,3 +148,114 @@ func TestReadonlyMounts(t *testing.T) {
}
}
}
func TestRemoveVolatileTempMount(t *testing.T) {
testCases := []struct {
desc string
input []Mount
expected []Mount
}{
{
desc: "remove volatile option from overlay mounts, ignore non overlay",
input: []Mount{
{
Type: "overlay",
Source: "overlay",
Options: []string{
"index=off",
"workdir=/path/to/snapshots/4/work",
"upperdir=/path/to/snapshots/4/fs",
"lowerdir=/path/to/snapshots/1/fs",
"volatile",
},
},
{
Type: "underlay",
Source: "underlay",
Options: []string{
"index=on",
"lowerdir=/another/path/to/snapshots/2/fs",
"volatile",
},
},
},
expected: []Mount{
{
Type: "overlay",
Source: "overlay",
Options: []string{
"index=off",
"workdir=/path/to/snapshots/4/work",
"upperdir=/path/to/snapshots/4/fs",
"lowerdir=/path/to/snapshots/1/fs",
},
},
{
Type: "underlay",
Source: "underlay",
Options: []string{
"index=on",
"lowerdir=/another/path/to/snapshots/2/fs",
"volatile",
},
},
},
},
{
desc: "return original slice since no volatile options on overlay",
input: []Mount{
{
Type: "overlay",
Source: "overlay",
Options: []string{
"index=off",
"workdir=/path/to/snapshots/4/work",
"upperdir=/path/to/snapshots/4/fs",
"lowerdir=/path/to/snapshots/1/fs",
},
},
{
Type: "underlay",
Source: "underlay",
Options: []string{
"index=on",
"lowerdir=/another/path/to/snapshots/2/fs",
"volatile",
},
},
},
expected: []Mount{
{
Type: "overlay",
Source: "overlay",
Options: []string{
"index=off",
"workdir=/path/to/snapshots/4/work",
"upperdir=/path/to/snapshots/4/fs",
"lowerdir=/path/to/snapshots/1/fs",
},
},
{
Type: "underlay",
Source: "underlay",
Options: []string{
"index=on",
"lowerdir=/another/path/to/snapshots/2/fs",
"volatile",
},
},
},
},
}
for _, tc := range testCases {
original := copyMounts(tc.input)
actual := removeVolatileTempMount(tc.input)
if !reflect.DeepEqual(actual, tc.expected) {
t.Fatalf("incorrectly modified mounts: %s.\n\n Expected: %v\n\n, Actual: %v", tc.desc, tc.expected, actual)
}
if !reflect.DeepEqual(original, tc.input) {
t.Fatalf("modified original mounts: %s.\n\n Expected: %v\n\n, Actual: %v", tc.desc, original, tc.input)
}
}
}