(t *testing.T)
| 198 | } |
| 199 | |
| 200 | func 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 | ) |
nothing calls this directly
no test coverage detected
searching dependent graphs…