MCPcopy
hub / github.com/opencontainers/runc / TestGetContainerState

Function TestGetContainerState

libcontainer/container_linux_test.go:149–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

147}
148
149func TestGetContainerState(t *testing.T) {
150 var (
151 pid = os.Getpid()
152 expectedMemoryPath = "/sys/fs/cgroup/memory/myid"
153 expectedNetworkPath = fmt.Sprintf("/proc/%d/ns/net", pid)
154 )
155 container := &Container{
156 id: "myid",
157 config: &configs.Config{
158 Namespaces: []configs.Namespace{
159 {Type: configs.NEWPID},
160 {Type: configs.NEWNS},
161 {Type: configs.NEWNET, Path: expectedNetworkPath},
162 {Type: configs.NEWUTS},
163 // emulate host for IPC
164 //{Type: configs.NEWIPC},
165 {Type: configs.NEWCGROUP},
166 },
167 },
168 initProcess: &mockProcess{
169 _pid: pid,
170 started: 10,
171 },
172 cgroupManager: &mockCgroupManager{
173 pids: []int{1, 2, 3},
174 paths: map[string]string{
175 "memory": expectedMemoryPath,
176 },
177 },
178 }
179 container.state = &createdState{c: container}
180 state, err := container.State()
181 if err != nil {
182 t.Fatal(err)
183 }
184 if state.InitProcessPid != pid {
185 t.Fatalf("expected pid %d but received %d", pid, state.InitProcessPid)
186 }
187 if state.InitProcessStartTime != 10 {
188 t.Fatalf("expected process start time 10 but received %d", state.InitProcessStartTime)
189 }
190 paths := state.CgroupPaths
191 if paths == nil {
192 t.Fatal("cgroup paths should not be nil")
193 }
194 if memPath := paths["memory"]; memPath != expectedMemoryPath {
195 t.Fatalf("expected memory path %q but received %q", expectedMemoryPath, memPath)
196 }
197 for _, ns := range container.config.Namespaces {
198 path := state.NamespacePaths[ns.Type]
199 if path == "" {
200 t.Fatalf("expected non nil namespace path for %s", ns.Type)
201 }
202 if ns.Type == configs.NEWNET {
203 if path != expectedNetworkPath {
204 t.Fatalf("expected path %q but received %q", expectedNetworkPath, path)
205 }
206 } else {

Callers

nothing calls this directly

Calls 1

StateMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…