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

Function TestDrupalBackdropOverwriteDdevSettings

pkg/ddevapp/settings_test.go:408–457  ·  view source on GitHub ↗

TestDrupalBackdropOverwriteDdevSettings ensures that if a settings.ddev.php file already exists, it is overwritten by the settings creation process.

(t *testing.T)

Source from the content-addressed store, hash-verified

406// TestDrupalBackdropOverwriteDdevSettings ensures that if a settings.ddev.php file already exists, it is overwritten by the
407// settings creation process.
408func TestDrupalBackdropOverwriteDdevSettings(t *testing.T) {
409 dir := testcommon.CreateTmpDir(t.Name())
410
411 app, err := ddevapp.NewApp(dir, true)
412 require.NoError(t, err)
413
414 err = os.MkdirAll(filepath.Join(dir, app.Docroot, "sites", "default"), 0777)
415 require.NoError(t, err)
416
417 for appType, relativeSettingsLocations := range drupalBackdropSettingsLocations {
418 app.Type = appType
419
420 relativeSettingsDdevLocation := relativeSettingsLocations.local
421 expectedSettingsDdevLocation := filepath.Join(dir, relativeSettingsDdevLocation)
422
423 // Ensure that a settings.ddev.php file exists, WITH the #ddev-generated signature
424 originalContents := "not empty " + nodeps.DdevFileSignature
425 settingsFile, err := os.Create(expectedSettingsDdevLocation)
426 require.NoError(t, err)
427 _, err = settingsFile.Write([]byte(originalContents))
428 require.NoError(t, err)
429
430 // Invoke the settings file creation process
431 _, err = app.CreateSettingsFile()
432 require.NoError(t, err)
433
434 // Ensure settings.ddev.php was overwritten; It had the signature in it
435 // so it was valid to overwrite. The original string should no longer be there.
436 containsOriginalString, err := fileutil.FgrepStringInFile(expectedSettingsDdevLocation, originalContents)
437 require.NoError(t, err)
438 require.False(t, containsOriginalString, "The file should not have contained the original string %s and it did not.", originalContents)
439
440 // Now do the whole thing again, but this time the settings.ddev.php does *not* have
441 // the #ddev-generated signature, so the file will be respected and not replaced
442 originalContents = "nearly empty "
443 settingsFile, err = os.Create(expectedSettingsDdevLocation)
444 require.NoError(t, err)
445 _, err = settingsFile.Write([]byte(originalContents))
446 require.NoError(t, err)
447
448 // Invoke the settings file creation process
449 _, err = app.CreateSettingsFile()
450 require.NoError(t, err)
451
452 // Ensure settings.ddev.php was overwritten with new contents
453 containsOriginalString, err = fileutil.FgrepStringInFile(expectedSettingsDdevLocation, originalContents)
454 require.NoError(t, err)
455 require.True(t, containsOriginalString, "Did not find %s in the settings file; it should have still been there", originalContents)
456 }
457}

Callers

nothing calls this directly

Calls 5

CreateTmpDirFunction · 0.92
NewAppFunction · 0.92
FgrepStringInFileFunction · 0.92
CreateSettingsFileMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected