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

Function TestGetRelativeWorkingDirectory

pkg/ddevapp/utils_test.go:60–88  ·  view source on GitHub ↗

TestGetRelativeWorkingDirectory validates GetRelativeWorkingDirectory

(t *testing.T)

Source from the content-addressed store, hash-verified

58
59// TestGetRelativeWorkingDirectory validates GetRelativeWorkingDirectory
60func TestGetRelativeWorkingDirectory(t *testing.T) {
61 assert := asrt.New(t)
62
63 origDir, _ := os.Getwd()
64 app := &ddevapp.DdevApp{}
65
66 site := TestSites[0]
67
68 t.Cleanup(func() {
69 err := os.Chdir(origDir)
70 assert.NoError(err)
71 err = app.Stop(true, false)
72 assert.NoError(err)
73 _ = os.RemoveAll("one")
74 })
75 // Make sure we have one app in existence
76 err := app.Init(site.Dir)
77 require.NoError(t, err)
78 err = os.MkdirAll(filepath.Join(app.AppRoot, "one", "two", "three", "four"), 0755)
79 require.NoError(t, err)
80
81 testCases := []string{filepath.Join("one"), filepath.Join("one", "two"), filepath.Join("one", "two", "three"), filepath.Join("one", "two", "three", "four")}
82 for _, c := range testCases {
83 err = os.Chdir(filepath.Join(app.AppRoot, c))
84 require.NoError(t, err)
85 relDir := app.GetRelativeWorkingDirectory()
86 assert.Equal(filepath.ToSlash(c), filepath.ToSlash(relDir))
87 }
88}

Callers

nothing calls this directly

Calls 5

StopMethod · 0.95
InitMethod · 0.95
CleanupMethod · 0.80
ChdirMethod · 0.80

Tested by

no test coverage detected