MCPcopy
hub / github.com/containerd/containerd / TestContainerStatus

Function TestContainerStatus

internal/cri/server/container_status_test.go:200–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestContainerStatus(t *testing.T) {
201 for _, test := range []struct {
202 desc string
203 exist bool
204 imageExist bool
205 startedAt int64
206 finishedAt int64
207 reason string
208 expectedState runtime.ContainerState
209 expectErr bool
210 }{
211 {
212 desc: "container created",
213 exist: true,
214 imageExist: true,
215 expectedState: runtime.ContainerState_CONTAINER_CREATED,
216 },
217 {
218 desc: "container running",
219 exist: true,
220 imageExist: true,
221 startedAt: time.Now().UnixNano(),
222 expectedState: runtime.ContainerState_CONTAINER_RUNNING,
223 },
224 {
225 desc: "container exited",
226 exist: true,
227 imageExist: true,
228 startedAt: time.Now().UnixNano(),
229 finishedAt: time.Now().UnixNano(),
230 reason: "test-reason",
231 expectedState: runtime.ContainerState_CONTAINER_EXITED,
232 },
233 {
234 desc: "container not exist",
235 exist: false,
236 imageExist: true,
237 expectErr: true,
238 },
239 {
240 desc: "image not exist",
241 exist: false,
242 imageExist: false,
243 expectErr: true,
244 },
245 } {
246 t.Run(test.desc, func(t *testing.T) {
247 c := newTestCRIService()
248 metadata, ctnr, status, image, expected := getContainerStatusTestData(t)
249 // Update status with test case.
250 status.StartedAt = test.startedAt
251 status.FinishedAt = test.finishedAt
252 status.Reason = test.reason
253 container, err := containerstore.NewContainer(
254 *metadata,
255 containerstore.WithFakeStatus(*status),
256 containerstore.WithContainer(ctnr),
257 )

Callers

nothing calls this directly

Calls 9

patchExceptedWithStateFunction · 0.85
newTestCRIServiceFunction · 0.70
RunMethod · 0.65
NewContainerMethod · 0.65
AddMethod · 0.65
GetStatusMethod · 0.65
ContainerStatusMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…