MCPcopy Index your code
hub / github.com/ddev/ddev / TestFindContainerByName

Function TestFindContainerByName

pkg/dockerutil/containers_test.go:356–393  ·  view source on GitHub ↗

TestFindContainerByName does a simple test of FindContainerByName()

(t *testing.T)

Source from the content-addressed store, hash-verified

354
355// TestFindContainerByName does a simple test of FindContainerByName()
356func 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
395func TestGetContainerEnv(t *testing.T) {
396 assert := asrt.New(t)

Callers

nothing calls this directly

Calls 4

RandomFilenameBaseFunction · 0.92
FindContainerByNameFunction · 0.92
RemoveContainerFunction · 0.92
RunSimpleContainerFunction · 0.92

Tested by

no test coverage detected