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

Function TestDdevExec

pkg/ddevapp/ddevapp_test.go:3130–3269  ·  view source on GitHub ↗

TestDdevExec tests the execution of commands inside a Docker container of a site.

(t *testing.T)

Source from the content-addressed store, hash-verified

3128
3129// TestDdevExec tests the execution of commands inside a Docker container of a site.
3130func TestDdevExec(t *testing.T) {
3131 assert := asrt.New(t)
3132 app := &ddevapp.DdevApp{}
3133 testDir, _ := os.Getwd()
3134
3135 site := TestSites[0]
3136 switchDir := site.Chdir()
3137 runTime := util.TimeTrackC(fmt.Sprintf("%s DdevExec", site.Name))
3138
3139 // Make a dummy service out of busybox
3140 err := fileutil.CopyFile(filepath.Join(testDir, "testdata", t.Name(), "docker-compose.busybox.yaml"), filepath.Join(site.Dir, ".ddev", "docker-compose.busybox.yaml"))
3141 assert.NoError(err)
3142
3143 err = app.Init(site.Dir)
3144 assert.NoError(err)
3145
3146 t.Cleanup(func() {
3147 app.Hooks = nil
3148 err = app.Stop(true, false)
3149 assert.NoError(err)
3150 err = app.WriteConfig()
3151 assert.NoError(err)
3152 _ = os.RemoveAll(filepath.Join(site.Dir, ".ddev", "docker-compose.busybox.yaml"))
3153 })
3154
3155 app.Hooks = map[string][]ddevapp.YAMLTask{"post-exec": {{"exec-host": "touch hello-post-exec-" + app.Name}}, "pre-exec": {{"exec-host": "touch hello-pre-exec-" + app.Name}}}
3156
3157 startErr := app.Start()
3158 if startErr != nil {
3159 logs, health, err := ddevapp.GetErrLogsFromApp(app, startErr)
3160 assert.NoError(err)
3161 t.Fatalf("app.Start() failed err=%v, health:\n%s\n\nlogs from broken container:\n=======\n%s\n========\n", startErr, health, logs)
3162 }
3163
3164 out, _, err := app.Exec(&ddevapp.ExecOpts{
3165 Service: "web",
3166 Cmd: "pwd",
3167 })
3168 assert.NoError(err)
3169 assert.Contains(out, "/var/www/html")
3170
3171 err = app.MutagenSyncFlush()
3172 assert.NoError(err)
3173
3174 assert.FileExists("hello-pre-exec-" + app.Name)
3175 assert.FileExists("hello-post-exec-" + app.Name)
3176 err = os.Remove("hello-pre-exec-" + app.Name)
3177 assert.NoError(err)
3178 err = os.Remove("hello-post-exec-" + app.Name)
3179 assert.NoError(err)
3180
3181 out, _, err = app.Exec(&ddevapp.ExecOpts{
3182 Service: "web",
3183 Dir: "/usr/local",
3184 Cmd: "pwd",
3185 })
3186 assert.NoError(err)
3187 assert.Contains(out, "/usr/local")

Callers

nothing calls this directly

Calls 15

InitMethod · 0.95
StopMethod · 0.95
WriteConfigMethod · 0.95
StartMethod · 0.95
ExecMethod · 0.95
MutagenSyncFlushMethod · 0.95
GetDBClientCommandMethod · 0.95
ExecWithTtyMethod · 0.95
TimeTrackCFunction · 0.92
CopyFileFunction · 0.92
GetErrLogsFromAppFunction · 0.92
GetDockerClientFunction · 0.92

Tested by

no test coverage detected