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

Function TestCmdAddon

cmd/ddev/cmd/addon_test.go:20–88  ·  view source on GitHub ↗

TestCmdAddon tests various `ddev add-on` commands.

(t *testing.T)

Source from the content-addressed store, hash-verified

18
19// TestCmdAddon tests various `ddev add-on` commands.
20func TestCmdAddon(t *testing.T) {
21 if !github.HasGitHubToken() {
22 t.Skip("Skipping because DDEV_GITHUB_TOKEN is not set")
23 }
24 assert := asrt.New(t)
25
26 origDir, _ := os.Getwd()
27 site := TestSites[0]
28 err := os.Chdir(site.Dir)
29 require.NoError(t, err)
30 app, err := ddevapp.GetActiveApp("")
31 require.NoError(t, err)
32
33 t.Cleanup(func() {
34 _, err = exec.RunHostCommand(DdevBin, "add-on", "remove", "memcached")
35 assert.NoError(err)
36 _, err = exec.RunHostCommand(DdevBin, "add-on", "remove", "example")
37 assert.NoError(err)
38
39 err = os.Chdir(origDir)
40 assert.NoError(err)
41 _ = os.RemoveAll(filepath.Join(globalconfig.GetGlobalDdevDir(), "commands/web/global-touched"))
42 _ = os.RemoveAll(filepath.Join(globalconfig.GetGlobalDdevDir(), "file-with-no-ddev-generated.txt"))
43 _ = os.RemoveAll(filepath.Join(globalconfig.GetGlobalDdevDir(), "globalextras"))
44 })
45
46 // Make sure 'ddev add-on list' works first
47 out, err := exec.RunHostCommand(DdevBin, "add-on", "list")
48 assert.NoError(err, "failed ddev add-on list: %v (%s)", err, out)
49 assert.Contains(out, "ddev/ddev-memcached")
50
51 tarballFile := filepath.Join(origDir, "testdata", t.Name(), "ddev-memcached.tar.gz")
52
53 // Test with many input styles
54 for _, arg := range []string{
55 "ddev/ddev-memcached",
56 "https://github.com/ddev/ddev-memcached/archive/refs/tags/v1.1.8.tar.gz",
57 tarballFile} {
58 out, err := exec.RunHostCommand(DdevBin, "add-on", "get", arg)
59 assert.NoError(err, "failed ddev add-on get %s", arg)
60 assert.Contains(out, "Installed ")
61 assert.FileExists(app.GetConfigPath("docker-compose.memcached.yaml"))
62 }
63
64 // Test with a directory-path input
65 exampleDir := filepath.Join(origDir, "testdata", t.Name(), "example-repo")
66 err = fileutil.TemplateStringToFile("no signature here", nil, app.GetConfigPath("file-with-no-ddev-generated.txt"))
67 require.NoError(t, err)
68 err = fileutil.TemplateStringToFile("no signature here", nil, filepath.Join(globalconfig.GetGlobalDdevDir(), "file-with-no-ddev-generated.txt"))
69 require.NoError(t, err)
70
71 out, err = exec.RunHostCommand(DdevBin, "add-on", "get", exampleDir)
72 assert.NoError(err, "output=%s", out)
73 assert.FileExists(app.GetConfigPath("i-have-been-touched"))
74 assert.FileExists(app.GetConfigPath("docker-compose.example.yaml"))
75 exists, err := fileutil.FgrepStringInFile(app.GetConfigPath("file-with-no-ddev-generated.txt"), "install should result in a warning")
76 require.NoError(t, err)
77 assert.False(exists, "the file with no ddev-generated.txt should not have been replaced")

Callers

nothing calls this directly

Calls 9

HasGitHubTokenFunction · 0.92
GetActiveAppFunction · 0.92
RunHostCommandFunction · 0.92
GetGlobalDdevDirFunction · 0.92
TemplateStringToFileFunction · 0.92
FgrepStringInFileFunction · 0.92
ChdirMethod · 0.80
CleanupMethod · 0.80
GetConfigPathMethod · 0.80

Tested by

no test coverage detected