(t *testing.T)
| 234 | } |
| 235 | |
| 236 | func TestGetExitCode(t *testing.T) { |
| 237 | tests := []struct { |
| 238 | name string |
| 239 | running bool |
| 240 | exitCode int |
| 241 | inspectErr error |
| 242 | expectErr bool |
| 243 | errContains string |
| 244 | expectedCode int |
| 245 | }{ |
| 246 | { |
| 247 | name: "successful exit code 0", |
| 248 | running: false, |
| 249 | exitCode: 0, |
| 250 | inspectErr: nil, |
| 251 | expectErr: false, |
| 252 | expectedCode: 0, |
| 253 | }, |
| 254 | { |
| 255 | name: "successful exit code 1", |
| 256 | running: false, |
| 257 | exitCode: 1, |
| 258 | inspectErr: nil, |
| 259 | expectErr: false, |
| 260 | expectedCode: 1, |
| 261 | }, |
| 262 | { |
| 263 | name: "container still running", |
| 264 | running: true, |
| 265 | exitCode: 0, |
| 266 | inspectErr: nil, |
| 267 | expectErr: true, |
| 268 | errContains: "still running", |
| 269 | expectedCode: -1, |
| 270 | }, |
| 271 | { |
| 272 | name: "inspect fails", |
| 273 | running: false, |
| 274 | exitCode: 0, |
| 275 | inspectErr: assert.AnError, |
| 276 | expectErr: true, |
| 277 | errContains: "failed to inspect", |
| 278 | expectedCode: -1, |
| 279 | }, |
| 280 | } |
| 281 | |
| 282 | for _, tt := range tests { |
| 283 | t.Run(tt.name, func(t *testing.T) { |
| 284 | as := assert.New(t) |
| 285 | |
| 286 | mockClient := &mockDockerClientForExitCode{ |
| 287 | inspectResp: dclient.ContainerInspectResult{ |
| 288 | Container: container.InspectResponse{ |
| 289 | State: &container.State{ |
| 290 | Running: tt.running, |
| 291 | ExitCode: tt.exitCode, |
| 292 | }, |
| 293 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…