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

Function TestDdevImportDB

pkg/ddevapp/ddevapp_test.go:1292–1667  ·  view source on GitHub ↗

TestDdevImportDB tests the functionality that is called when "ddev import-db" is executed

(t *testing.T)

Source from the content-addressed store, hash-verified

1290
1291// TestDdevImportDB tests the functionality that is called when "ddev import-db" is executed
1292func TestDdevImportDB(t *testing.T) {
1293 // Don't run this unless GOTEST_SHORT is unset; it doesn't need to be run everywhere.
1294 if os.Getenv("GOTEST_SHORT") != "" {
1295 t.Skip("Skip because GOTEST_SHORT is set")
1296 }
1297 assert := asrt.New(t)
1298 app := &ddevapp.DdevApp{}
1299 origDir, _ := os.Getwd()
1300
1301 site := TestSites[0]
1302
1303 runTime := util.TimeTrackC(fmt.Sprintf("%s %s", site.Name, t.Name()))
1304
1305 testcommon.ClearDockerEnv()
1306 err := app.Init(site.Dir)
1307 assert.NoError(err)
1308
1309 t.Cleanup(func() {
1310 runTime()
1311 err = app.Stop(true, false)
1312 assert.NoError(err)
1313 app.Hooks = nil
1314 app.Database.Type = nodeps.MariaDB
1315 app.Database.Version = nodeps.MariaDBDefaultVersion
1316 err = app.WriteConfig()
1317 assert.NoError(err)
1318 _ = os.Remove(filepath.Join(app.AppRoot, "hello-pre-import-db-"+app.Name))
1319 _ = os.Remove(filepath.Join(app.AppRoot, "hello-post-import-db-"+app.Name))
1320 for _, dbType := range []string{nodeps.Postgres, nodeps.MariaDB} {
1321 err = dockerutil.RemoveVolume(app.Name + "-" + dbType)
1322 require.NoError(t, err)
1323 }
1324 })
1325
1326 c := make(map[string]string)
1327
1328 for _, dbType := range []string{nodeps.MariaDB, nodeps.Postgres} {
1329 err = app.Stop(true, false)
1330 require.NoError(t, err)
1331
1332 app.Database = ddevapp.DatabaseDesc{
1333 Type: dbType,
1334 Version: nodeps.MariaDBDefaultVersion,
1335 }
1336 if dbType == nodeps.Postgres {
1337 app.Database.Version = nodeps.PostgresDefaultVersion
1338 }
1339 err = app.WriteConfig()
1340 assert.NoError(err)
1341
1342 err = app.Start()
1343 require.NoError(t, err)
1344
1345 c[nodeps.MariaDB] = fmt.Sprintf(`%s -N -e 'DROP DATABASE IF EXISTS test;'`, app.GetDBClientCommand())
1346 c[nodeps.Postgres] = `echo "SELECT 'DROP DATABASE test' WHERE EXISTS (SELECT FROM pg_database WHERE datname = 'test')\gexec" | psql -v ON_ERROR_STOP=1 -d postgres`
1347 out, stderr, err := app.Exec(&ddevapp.ExecOpts{
1348 Service: "db",
1349 Cmd: c[dbType],

Callers

nothing calls this directly

Calls 15

InitMethod · 0.95
StopMethod · 0.95
WriteConfigMethod · 0.95
StartMethod · 0.95
GetDBClientCommandMethod · 0.95
ExecMethod · 0.95
ImportDBMethod · 0.95
TimeTrackCFunction · 0.92
ClearDockerEnvFunction · 0.92
RemoveVolumeFunction · 0.92
FileExistsFunction · 0.92
FgrepStringInFileFunction · 0.92

Tested by

no test coverage detected