From 41c35810f2ab71e19f0ed13cbdaf3ff218208ff5 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Sat, 22 Oct 2016 11:31:15 +0800 Subject: [PATCH] add test cases about host ns Signed-off-by: Ce Gao --- .../configs/validate/validator_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libcontainer/configs/validate/validator_test.go b/libcontainer/configs/validate/validator_test.go index c2100d3c9..649e02844 100644 --- a/libcontainer/configs/validate/validator_test.go +++ b/libcontainer/configs/validate/validator_test.go @@ -201,3 +201,38 @@ func TestValidateSysctl(t *testing.T) { } } } + +func TestValidateSysctlWithSameNs(t *testing.T) { + config := &configs.Config{ + Rootfs: "/var", + Sysctl: map[string]string{"net.ctl": "ctl"}, + Namespaces: configs.Namespaces( + []configs.Namespace{ + { + Type: configs.NEWNET, + Path: "/proc/self/ns/net", + }, + }, + ), + } + + validator := validate.New() + err := validator.Validate(config) + if err == nil { + t.Error("Expected error to occur but it was nil") + } +} + +func TestValidateSysctlWithoutNETNamespace(t *testing.T) { + config := &configs.Config{ + Rootfs: "/var", + Sysctl: map[string]string{"net.ctl": "ctl"}, + Namespaces: []configs.Namespace{}, + } + + validator := validate.New() + err := validator.Validate(config) + if err == nil { + t.Error("Expected error to occur but it was nil") + } +}