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

Function TestGetActiveAppRoot

cmd/ddev/cmd/root_test.go:138–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestGetActiveAppRoot(t *testing.T) {
139 assert := asrt.New(t)
140
141 // Looking for active approot here should fail, because there is none
142 _, err := ddevapp.GetActiveAppRoot("")
143 assert.Contains(err.Error(), "Please specify a project name or change directories")
144
145 // There is also no project named "potato"
146 _, err = ddevapp.GetActiveAppRoot("potato")
147 assert.Error(err)
148
149 // However, TestSites[0] is running, so we should find it.
150 appRoot, err := ddevapp.GetActiveAppRoot(TestSites[0].Name)
151 assert.NoError(err)
152 assert.Equal(TestSites[0].Dir, appRoot)
153
154 origDir, _ := os.Getwd()
155 err = os.Chdir(TestSites[0].Dir)
156 require.NoError(t, err)
157
158 // We should also now be able to get it in the project directory
159 // since it's running and we're in the directory
160 appRoot, err = ddevapp.GetActiveAppRoot("")
161 assert.NoError(err)
162 assert.Equal(TestSites[0].Dir, appRoot)
163
164 // Make sure that shell commands show in regular `ddev` output - launch should show
165 b := util.FindBashPath()
166 _, err = exec.RunHostCommand(b, "-c", fmt.Sprintf("%s | grep launch", DdevBin))
167 assert.NoError(err)
168
169 // And we should be able to stop it and find it as well
170 app, err := ddevapp.GetActiveApp("")
171 require.NoError(t, err)
172 err = app.Stop(false, true)
173 require.NoError(t, err)
174
175 t.Cleanup(func() {
176 err = os.Chdir(origDir)
177 assert.NoError(err)
178 // Leave it running in case anybody cares
179 err = app.Start()
180 assert.NoError(err)
181 })
182
183 appRoot, err = ddevapp.GetActiveAppRoot(app.Name)
184 assert.NoError(err)
185 assert.Equal(TestSites[0].Dir, appRoot)
186}
187
188// TestCreateGlobalDdevDir checks to make sure that DDEV will create a ~/.ddev (and updatecheck)
189func TestCreateGlobalDdevDir(t *testing.T) {

Callers

nothing calls this directly

Calls 9

GetActiveAppRootFunction · 0.92
FindBashPathFunction · 0.92
RunHostCommandFunction · 0.92
GetActiveAppFunction · 0.92
ErrorMethod · 0.80
ChdirMethod · 0.80
StopMethod · 0.80
CleanupMethod · 0.80
StartMethod · 0.80

Tested by

no test coverage detected