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"
|
|
|
|
"gotest.tools/assert"
|
2018-12-11 09:15:04 -05:00
|
|
|
"gotest.tools/fs"
|
|
|
|
"gotest.tools/icmd"
|
|
|
|
)
|
|
|
|
|
2019-02-18 06:49:41 -05:00
|
|
|
func prepare(t *testing.T) (func(args ...string) icmd.Cmd, *configfile.ConfigFile, func()) {
|
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
|
|
|
|
|
|
|
}
|