...
1 package configs
2
3 import (
4 "testing"
5 )
6
7 var HookNameList = []HookName{Prestart, CreateRuntime, CreateContainer, StartContainer, Poststart, Poststop}
8
9 func TestRemoveNamespace(t *testing.T) {
10 ns := Namespaces{
11 {Type: NEWNET},
12 }
13 if !ns.Remove(NEWNET) {
14 t.Fatal("NEWNET was not removed")
15 }
16 if len(ns) != 0 {
17 t.Fatalf("namespaces should have 0 items but reports %d", len(ns))
18 }
19 }
20
21 func TestHostRootUIDNoUSERNS(t *testing.T) {
22 config := &Config{
23 Namespaces: Namespaces{},
24 }
25 uid, err := config.HostRootUID()
26 if err != nil {
27 t.Fatal(err)
28 }
29 if uid != 0 {
30 t.Fatalf("expected uid 0 with no USERNS but received %d", uid)
31 }
32 }
33
34 func TestHostRootUIDWithUSERNS(t *testing.T) {
35 config := &Config{
36 Namespaces: Namespaces{{Type: NEWUSER}},
37 UidMappings: []IDMap{
38 {
39 ContainerID: 0,
40 HostID: 1000,
41 Size: 1,
42 },
43 },
44 }
45 uid, err := config.HostRootUID()
46 if err != nil {
47 t.Fatal(err)
48 }
49 if uid != 1000 {
50 t.Fatalf("expected uid 1000 with no USERNS but received %d", uid)
51 }
52 }
53
54 func TestHostRootGIDNoUSERNS(t *testing.T) {
55 config := &Config{
56 Namespaces: Namespaces{},
57 }
58 uid, err := config.HostRootGID()
59 if err != nil {
60 t.Fatal(err)
61 }
62 if uid != 0 {
63 t.Fatalf("expected gid 0 with no USERNS but received %d", uid)
64 }
65 }
66
67 func TestHostRootGIDWithUSERNS(t *testing.T) {
68 config := &Config{
69 Namespaces: Namespaces{{Type: NEWUSER}},
70 GidMappings: []IDMap{
71 {
72 ContainerID: 0,
73 HostID: 1000,
74 Size: 1,
75 },
76 },
77 }
78 uid, err := config.HostRootGID()
79 if err != nil {
80 t.Fatal(err)
81 }
82 if uid != 1000 {
83 t.Fatalf("expected gid 1000 with no USERNS but received %d", uid)
84 }
85 }
86
View as plain text