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

Function TestDdevDescribe

pkg/ddevapp/ddevapp_test.go:3328–3426  ·  view source on GitHub ↗

TestDdevDescribe tests that the describe command works properly on a running and also a stopped project.

(t *testing.T)

Source from the content-addressed store, hash-verified

3326// TestDdevDescribe tests that the describe command works properly on a running
3327// and also a stopped project.
3328func TestDdevDescribe(t *testing.T) {
3329 origDir, _ := os.Getwd()
3330 assert := asrt.New(t)
3331 app := &ddevapp.DdevApp{}
3332
3333 site := TestSites[0]
3334
3335 testcommon.ClearDockerEnv()
3336 err := app.Init(site.Dir)
3337 assert.NoError(err)
3338
3339 // Copy testdata docker-compose file to test x-ddev.describe functionality
3340 testdataDir := filepath.Join(origDir, "testdata", "TestDdevDescribe")
3341 composeFile := filepath.Join(testdataDir, "docker-compose.testservice.yaml")
3342 destFile := filepath.Join(app.AppRoot, ".ddev", "docker-compose.testservice.yaml")
3343 err = fileutil.CopyFile(composeFile, destFile)
3344 require.NoError(t, err)
3345
3346 t.Cleanup(func() {
3347 err = os.Chdir(origDir)
3348 assert.NoError(err)
3349 err = app.Stop(true, false)
3350 assert.NoError(err)
3351 app.Hooks = nil
3352 err = app.WriteConfig()
3353 assert.NoError(err)
3354 // Clean up the copied docker-compose file
3355 _ = os.Remove(destFile)
3356 })
3357 err = os.Chdir(site.Dir)
3358 require.NoError(t, err)
3359 app.Hooks = map[string][]ddevapp.YAMLTask{"post-describe": {{"exec-host": "touch ${DDEV_APPROOT}/hello-post-describe-" + app.Name}}, "pre-describe": {{"exec-host": "touch ${DDEV_APPROOT}/hello-pre-describe-" + app.Name}}}
3360 err = app.WriteConfig()
3361 require.NoError(t, err)
3362
3363 // Test both stopped and running states
3364 for _, state := range []struct {
3365 name string
3366 running bool
3367 }{
3368 {"stopped", false},
3369 {"running", true},
3370 } {
3371 t.Run(state.name, func(t *testing.T) {
3372 if state.running {
3373 startErr := app.StartAndWait(0)
3374
3375 // If we have a problem starting, get the container logs and output.
3376 if startErr != nil {
3377 out, logsErr := app.CaptureLogs("web", false, "")
3378 assert.NoError(logsErr)
3379
3380 healthcheck, inspectErr := exec.RunCommandPipe("sh", []string{"-c", fmt.Sprintf("docker inspect ddev-%s-web|jq -r '.[0].State.Health.Log[-1]'", app.Name)})
3381 assert.NoError(inspectErr)
3382
3383 t.Fatalf("app.StartAndWait(%s) failed: %v, \nweb container healthcheck='%s', \n== web container logs=\n%s\n== END web container logs ==", site.Name, err, healthcheck, out)
3384 }
3385 } else {

Callers

nothing calls this directly

Calls 15

InitMethod · 0.95
StopMethod · 0.95
WriteConfigMethod · 0.95
StartAndWaitMethod · 0.95
CaptureLogsMethod · 0.95
DockerEnvMethod · 0.95
DescribeMethod · 0.95
GetNameMethod · 0.95
GetAppRootMethod · 0.95
GetPhpVersionMethod · 0.95
ClearDockerEnvFunction · 0.92

Tested by

no test coverage detected