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

Function TestCustomCommands

cmd/ddev/cmd/commands_test.go:24–309  ·  view source on GitHub ↗

TestCustomCommands does basic checks to make sure custom commands work OK.

(t *testing.T)

Source from the content-addressed store, hash-verified

22
23// TestCustomCommands does basic checks to make sure custom commands work OK.
24func TestCustomCommands(t *testing.T) {
25 assert := asrt.New(t)
26 runTime := util.TimeTrackC(t.Name())
27
28 origDir, _ := os.Getwd()
29
30 site := TestSites[0]
31 err := os.Chdir(site.Dir)
32 require.NoError(t, err)
33
34 app, err := ddevapp.NewApp("", false)
35 assert.NoError(err)
36
37 tmpXdgConfigHomeDir := testcommon.CopyGlobalDdevDir(t)
38
39 testdataCustomCommandsDir := filepath.Join(origDir, "testdata", t.Name())
40
41 origType := app.Type
42 t.Cleanup(func() {
43 err = os.Chdir(origDir)
44 assert.NoError(err)
45 err = app.Stop(true, false)
46 assert.NoError(err)
47 testcommon.ResetGlobalDdevDir(t, tmpXdgConfigHomeDir)
48 runTime()
49 app.Type = origType
50 err = app.WriteConfig()
51 assert.NoError(err)
52 _ = fileutil.PurgeDirectory(filepath.Join(site.Dir, ".ddev", "commands"))
53 })
54 // We must start the app before copying commands, so they don't get copied over
55 err = app.Start()
56 require.NoError(t, err)
57
58 tmpHomeGlobalCommandsDir := filepath.Join(globalconfig.GetGlobalDdevDir(), "commands")
59 err = os.RemoveAll(tmpHomeGlobalCommandsDir)
60 assert.NoError(err)
61
62 projectCommandsDir := app.GetConfigPath("commands")
63 err = fileutil.CopyDir(filepath.Join(testdataCustomCommandsDir, "global_commands"), tmpHomeGlobalCommandsDir)
64 require.NoError(t, err)
65
66 // Must sync our added commands before using them.
67 err = app.MutagenSyncFlush()
68 assert.NoError(err)
69
70 // We need to run some assertions outside of the context of a project first
71 err = os.Chdir(tmpXdgConfigHomeDir)
72 require.NoError(t, err)
73
74 // Check that only global host commands with the XXX annotation display here
75 out, err := exec.RunHostCommand(DdevBin)
76 assert.NoError(err)
77 assert.Contains(out, "testhostglobal-noproject global (global shell host container command)")
78 assert.NotContains(out, "testhostcmd project (shell host container command)")
79 assert.NotContains(out, "testwebcmd project (shell web container command)")
80 assert.NotContains(out, "testhostglobal global (global shell host container command)")
81 assert.NotContains(out, "testwebglobal global (global shell web container command)")

Callers

nothing calls this directly

Calls 15

TimeTrackCFunction · 0.92
NewAppFunction · 0.92
CopyGlobalDdevDirFunction · 0.92
ResetGlobalDdevDirFunction · 0.92
PurgeDirectoryFunction · 0.92
GetGlobalDdevDirFunction · 0.92
CopyDirFunction · 0.92
RunHostCommandFunction · 0.92
FileExistsFunction · 0.92
ChdirMethod · 0.80
CleanupMethod · 0.80
StopMethod · 0.80

Tested by

no test coverage detected