Skip to content

Commit d91b9d5

Browse files
committed
test: Add test for plugin directory environment variable expansion
Signed-off-by: Paulchen <[email protected]>
1 parent 68cde6f commit d91b9d5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cli-plugins/manager/manager_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ func TestListPluginCandidatesEmpty(t *testing.T) {
8686
assert.Assert(t, len(candidates) == 0)
8787
}
8888

89+
func TestPluginDirEnvironmentVariableExpansion(t *testing.T) {
90+
pluginDir := "plugins1"
91+
t.Setenv("MY_PLUGIN_DIR", pluginDir)
92+
dir := fs.NewDir(t, t.Name(),
93+
fs.WithDir("${MY_PLUGIN_DIR}",
94+
fs.WithFile("docker-plugin1", ""),
95+
),
96+
)
97+
defer dir.Remove()
98+
99+
t.Setenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS", dir.Join(pluginDir))
100+
101+
cli := test.NewFakeCli(nil)
102+
cli.SetConfigFile(&configfile.ConfigFile{CLIPluginsExtraDirs: []string{"$DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"}})
103+
104+
pluginDirs := getPluginDirs(cli.ConfigFile())
105+
expected := []string{
106+
dir.Join(pluginDir),
107+
filepath.Join(config.Dir(), "cli-plugins"),
108+
}
109+
expected = append(expected, defaultSystemPluginDirs...)
110+
assert.DeepEqual(t, expected, pluginDirs)
111+
}
112+
89113
// Regression test for https://github.com/docker/cli/issues/5643.
90114
// Check that inaccessible directories that come before accessible ones are ignored
91115
// and do not prevent the latter from being processed.

0 commit comments

Comments
 (0)