github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/e2e/cli-plugins/util_test.go (about)

     1  package cliplugins
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/docker/cli/cli/config"
     9  	"github.com/docker/cli/cli/config/configfile"
    10  	"gotest.tools/v3/assert"
    11  	"gotest.tools/v3/fs"
    12  	"gotest.tools/v3/icmd"
    13  )
    14  
    15  func prepare(t *testing.T) (func(args ...string) icmd.Cmd, *configfile.ConfigFile, func()) {
    16  	cfg := fs.NewDir(t, "plugin-test",
    17  		fs.WithFile("config.json", fmt.Sprintf(`{"cliPluginsExtraDirs": [%q]}`, os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"))),
    18  	)
    19  	run := func(args ...string) icmd.Cmd {
    20  		return icmd.Command("docker", append([]string{"--config", cfg.Path()}, args...)...)
    21  	}
    22  	cleanup := func() {
    23  		cfg.Remove()
    24  	}
    25  	cfgfile, err := config.Load(cfg.Path())
    26  	assert.NilError(t, err)
    27  
    28  	return run, cfgfile, cleanup
    29  
    30  }