Skip to content

Commit 41c3581

Browse files
committed
add test cases about host ns
Signed-off-by: Ce Gao <[email protected]>
1 parent bc84f83 commit 41c3581

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

libcontainer/configs/validate/validator_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,38 @@ func TestValidateSysctl(t *testing.T) {
201201
}
202202
}
203203
}
204+
205+
func TestValidateSysctlWithSameNs(t *testing.T) {
206+
config := &configs.Config{
207+
Rootfs: "/var",
208+
Sysctl: map[string]string{"net.ctl": "ctl"},
209+
Namespaces: configs.Namespaces(
210+
[]configs.Namespace{
211+
{
212+
Type: configs.NEWNET,
213+
Path: "/proc/self/ns/net",
214+
},
215+
},
216+
),
217+
}
218+
219+
validator := validate.New()
220+
err := validator.Validate(config)
221+
if err == nil {
222+
t.Error("Expected error to occur but it was nil")
223+
}
224+
}
225+
226+
func TestValidateSysctlWithoutNETNamespace(t *testing.T) {
227+
config := &configs.Config{
228+
Rootfs: "/var",
229+
Sysctl: map[string]string{"net.ctl": "ctl"},
230+
Namespaces: []configs.Namespace{},
231+
}
232+
233+
validator := validate.New()
234+
err := validator.Validate(config)
235+
if err == nil {
236+
t.Error("Expected error to occur but it was nil")
237+
}
238+
}

0 commit comments

Comments
 (0)