2018-12-11 09:15:04 -05:00
|
|
|
package cliplugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2019-02-18 06:49:41 -05:00
|
|
|
"github.com/docker/cli/cli/config"
|
|
|
|
"github.com/docker/cli/cli/config/configfile"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/fs"
|
|
|
|
"gotest.tools/v3/icmd"
|
2018-12-11 09:15:04 -05:00
|
|
|
)
|
|
|
|
|
2019-02-18 06:49:41 -05:00
|
|
|
func prepare(t *testing.T) (func(args ...string) icmd.Cmd, *configfile.ConfigFile, func()) {
|
2023-11-20 05:10:29 -05:00
|
|
|
t.Helper()
|
2018-12-11 09:15:04 -05:00
|
|
|
cfg := fs.NewDir(t, "plugin-test",
|
|
|
|
fs.WithFile("config.json", fmt.Sprintf(`{"cliPluginsExtraDirs": [%q]}`, os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"))),
|
|
|
|
)
|
|
|
|
run := func(args ...string) icmd.Cmd {
|
|
|
|
return icmd.Command("docker", append([]string{"--config", cfg.Path()}, args...)...)
|
|
|
|
}
|
|
|
|
cleanup := func() {
|
|
|
|
cfg.Remove()
|
|
|
|
}
|
2019-02-18 06:49:41 -05:00
|
|
|
cfgfile, err := config.Load(cfg.Path())
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
return run, cfgfile, cleanup
|
2018-12-11 09:15:04 -05:00
|
|
|
}
|