TestFindContainerByName does a simple test of FindContainerByName()
(t *testing.T)
| 354 | |
| 355 | // TestFindContainerByName does a simple test of FindContainerByName() |
| 356 | func TestFindContainerByName(t *testing.T) { |
| 357 | assert := asrt.New(t) |
| 358 | |
| 359 | pwd, _ := os.Getwd() |
| 360 | pwd, _ = filepath.Abs(pwd) |
| 361 | testdata := filepath.Join(pwd, "testdata") |
| 362 | assert.DirExists(testdata) |
| 363 | containerName := t.Name() + fileutil.RandomFilenameBase() |
| 364 | |
| 365 | // Make sure we don't already have one running |
| 366 | c, err := dockerutil.FindContainerByName(containerName) |
| 367 | assert.NoError(err) |
| 368 | if err == nil && c != nil { |
| 369 | err = dockerutil.RemoveContainer(c.ID) |
| 370 | assert.NoError(err) |
| 371 | } |
| 372 | |
| 373 | // Run a container, don't remove it. |
| 374 | cID, _, err := dockerutil.RunSimpleContainer(versionconstants.UtilitiesImage, containerName, []string{"sleep", "2"}, nil, nil, nil, "25", false, false, nil, nil, nil) |
| 375 | require.NoError(t, err) |
| 376 | |
| 377 | defer func() { |
| 378 | _ = dockerutil.RemoveContainer(cID) |
| 379 | }() |
| 380 | |
| 381 | // Now find the container by name |
| 382 | c, err = dockerutil.FindContainerByName(containerName) |
| 383 | assert.NoError(err) |
| 384 | require.NotNil(t, c) |
| 385 | // Remove it |
| 386 | err = dockerutil.RemoveContainer(c.ID) |
| 387 | assert.NoError(err) |
| 388 | |
| 389 | // Verify that we no longer find it. |
| 390 | c, err = dockerutil.FindContainerByName(containerName) |
| 391 | assert.NoError(err) |
| 392 | assert.Nil(c) |
| 393 | } |
| 394 | |
| 395 | func TestGetContainerEnv(t *testing.T) { |
| 396 | assert := asrt.New(t) |
nothing calls this directly
no test coverage detected