pkg/cri/opts.WithoutRunMount -> oci.WithoutRunMount

Move `pkg/cri/opts.WithoutRunMount` function to `oci.WithoutRunMount`
so that it can be used without dependency on CRI.

Also add `oci.WithoutMounts(dests ...string)` for generality.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2021-04-06 19:51:17 +09:00
parent 85041ffe58
commit 8ba8533bde
6 changed files with 86 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
@@ -601,3 +602,59 @@ func getShmSize(opts []string) string {
}
return ""
}
func TestWithoutMounts(t *testing.T) {
t.Parallel()
var s Spec
x := func(s string) string {
if runtime.GOOS == "windows" {
return filepath.Join("C:\\", filepath.Clean(s))
}
return s
}
opts := []SpecOpts{
WithMounts([]specs.Mount{
{
Destination: x("/dst1"),
Source: x("/src1"),
},
{
Destination: x("/dst2"),
Source: x("/src2"),
},
{
Destination: x("/dst3"),
Source: x("/src3"),
},
}),
WithoutMounts(x("/dst2"), x("/dst3")),
WithMounts([]specs.Mount{
{
Destination: x("/dst4"),
Source: x("/src4"),
},
}),
}
expected := []specs.Mount{
{
Destination: x("/dst1"),
Source: x("/src1"),
},
{
Destination: x("/dst4"),
Source: x("/src4"),
},
}
for _, opt := range opts {
if err := opt(nil, nil, nil, &s); err != nil {
t.Fatal(err)
}
}
if !reflect.DeepEqual(expected, s.Mounts) {
t.Fatalf("expected %+v, got %+v", expected, s.Mounts)
}
}