containerd: Add WithNamespace to replace namespace
Signed-off-by: Samuel Karp <skarp@amazon.com>
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
package containerd
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
func TestGenerateSpec(t *testing.T) {
|
||||
s, err := GenerateSpec()
|
||||
@@ -56,3 +60,23 @@ func TestSpecWithTTY(t *testing.T) {
|
||||
t.Errorf("xterm not set in env for TTY")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithLinuxNamespace(t *testing.T) {
|
||||
replacedNS := specs.LinuxNamespace{Type: specs.NetworkNamespace, Path: "/var/run/netns/test"}
|
||||
s, err := GenerateSpec(WithLinuxNamespace(replacedNS))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
defaultNS := defaultNamespaces()
|
||||
found := false
|
||||
for i, ns := range s.Linux.Namespaces {
|
||||
if ns == replacedNS && !found {
|
||||
found = true
|
||||
continue
|
||||
}
|
||||
if defaultNS[i] != ns {
|
||||
t.Errorf("ns at %d does not match set %q != %q", i, defaultNS[i], ns)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user