MCPcopy Create free account
hub / github.com/ddev/ddev / TestGetGlobalDdevDirLocation

Function TestGetGlobalDdevDirLocation

cmd/ddev/cmd/root_test.go:308–341  ·  view source on GitHub ↗

TestGetGlobalDdevDirLocation checks to make sure that DDEV will use the correct location for its global config. The correct location is: ${XDG_CONFIG_HOME}/ddev if XDG_CONFIG_HOME is set or ~/.ddev if it exists or ~/.config/ddev if it exists

(t *testing.T)

Source from the content-addressed store, hash-verified

306// ~/.ddev if it exists or
307// ~/.config/ddev if it exists
308func TestGetGlobalDdevDirLocation(t *testing.T) {
309 // Test when $XDG_CONFIG_HOME is not set
310 t.Setenv("XDG_CONFIG_HOME", "")
311 ddevDir := globalconfig.GetGlobalDdevDirLocation()
312 // Original ~/.ddev dir location
313 originalGlobalDdevDir := filepath.Join(util.GetHomeDir(), ".ddev")
314 // If test runs on Linux machine, where ~/.config/ddev is used
315 // if ~/.ddev does not exist:
316 if nodeps.IsLinux() && !fileutil.IsDirectory(originalGlobalDdevDir) {
317 linuxDdevDir := filepath.Join(util.GetHomeDir(), ".config", "ddev")
318 if fileutil.IsDirectory(linuxDdevDir) {
319 originalGlobalDdevDir = linuxDdevDir
320 }
321 }
322 require.Equal(t, ddevDir, originalGlobalDdevDir)
323 // Test when $XDG_CONFIG_HOME is set
324 tmpDir := testcommon.CreateTmpDir(t.Name())
325 t.Cleanup(func() {
326 _ = os.RemoveAll(tmpDir)
327 })
328 t.Setenv("XDG_CONFIG_HOME", tmpDir)
329 // Make sure that the tmpDir/ddev doesn't exist.
330 _, err := os.Stat(filepath.Join(tmpDir, "ddev"))
331 require.Error(t, err)
332 require.True(t, os.IsNotExist(err))
333 // Check that we can get the correct location
334 ddevDir = globalconfig.GetGlobalDdevDirLocation()
335 require.Equal(t, ddevDir, filepath.Join(tmpDir, "ddev"))
336 // When $XDG_CONFIG_HOME is not set,
337 // it should use the default location
338 t.Setenv("XDG_CONFIG_HOME", "")
339 ddevDir = globalconfig.GetGlobalDdevDirLocation()
340 require.Equal(t, ddevDir, originalGlobalDdevDir)
341}
342
343// TestPoweroffOnNewVersion checks that a poweroff happens when a new DDEV version is deployed
344func TestPoweroffOnNewVersion(t *testing.T) {

Callers

nothing calls this directly

Calls 7

GetGlobalDdevDirLocationFunction · 0.92
GetHomeDirFunction · 0.92
IsLinuxFunction · 0.92
IsDirectoryFunction · 0.92
CreateTmpDirFunction · 0.92
CleanupMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected