TestEnvironmentVariables tests to make sure that documented environment variables appear in the web container and on the host.
(t *testing.T)
| 4505 | // TestEnvironmentVariables tests to make sure that documented environment variables appear |
| 4506 | // in the web container and on the host. |
| 4507 | func TestEnvironmentVariables(t *testing.T) { |
| 4508 | assert := asrt.New(t) |
| 4509 | |
| 4510 | origDir, _ := os.Getwd() |
| 4511 | t.Setenv("DDEV_DEBUG", "") |
| 4512 | customCmd := filepath.Join(origDir, "testdata", t.Name(), "showhostenvvar") |
| 4513 | site := TestSites[0] |
| 4514 | |
| 4515 | app, err := ddevapp.NewApp(site.Dir, false) |
| 4516 | assert.NoError(err) |
| 4517 | err = os.Chdir(site.Dir) |
| 4518 | assert.NoError(err) |
| 4519 | customCmdDest := app.GetConfigPath("commands/host/" + "showhostenvvar") |
| 4520 | |
| 4521 | err = os.MkdirAll(filepath.Dir(customCmdDest), 0755) |
| 4522 | require.NoError(t, err) |
| 4523 | err = fileutil.CopyFile(customCmd, customCmdDest) |
| 4524 | require.NoError(t, err) |
| 4525 | |
| 4526 | dbFamily := "mysql" |
| 4527 | if app.Database.Type == "postgres" { |
| 4528 | // 'postgres' & 'postgresql' are both valid, but we'll go with the shorter one. |
| 4529 | dbFamily = "postgres" |
| 4530 | } |
| 4531 | |
| 4532 | t.Cleanup(func() { |
| 4533 | err = os.RemoveAll(customCmdDest) |
| 4534 | assert.NoError(err) |
| 4535 | err = app.Stop(true, false) |
| 4536 | assert.NoError(err) |
| 4537 | err = os.Chdir(origDir) |
| 4538 | assert.NoError(err) |
| 4539 | }) |
| 4540 | |
| 4541 | err = app.Restart() |
| 4542 | require.NoError(t, err) |
| 4543 | |
| 4544 | primaryURL := app.GetPrimaryURL() |
| 4545 | scheme, primaryURLWithoutPort, primaryURLPort := nodeps.ParseURL(primaryURL) |
| 4546 | uidStr, gidStr, username := dockerutil.GetContainerUser() |
| 4547 | |
| 4548 | // This set of webContainerExpectations should be maintained to match the list in the docs |
| 4549 | webContainerExpectations := map[string]string{ |
| 4550 | "DDEV_APPROOT": "/var/www/html", |
| 4551 | "DDEV_DATABASE": app.Database.Type + ":" + app.Database.Version, |
| 4552 | "DDEV_DATABASE_FAMILY": dbFamily, |
| 4553 | "DDEV_DOCROOT": app.GetDocroot(), |
| 4554 | "DDEV_FILES_DIR": app.GetContainerUploadDir(), |
| 4555 | "DDEV_FILES_DIRS": strings.Join(app.GetContainerUploadDirs(), ","), |
| 4556 | "DDEV_GID": gidStr, |
| 4557 | "DDEV_HOSTNAME": app.GetHostname(), |
| 4558 | "DDEV_MUTAGEN_ENABLED": strconv.FormatBool(app.IsMutagenEnabled()), |
| 4559 | "DDEV_PHP_VERSION": app.PHPVersion, |
| 4560 | "DDEV_PRIMARY_URL": primaryURL, |
| 4561 | "DDEV_PRIMARY_URL_PORT": primaryURLPort, |
| 4562 | "DDEV_PRIMARY_URL_WITHOUT_PORT": primaryURLWithoutPort, |
| 4563 | "DDEV_PROJECT": app.Name, |
| 4564 | "DDEV_PROJECT_TYPE": app.Type, |
nothing calls this directly
no test coverage detected