github.com/ali-iotechsys/cli@v20.10.0+incompatible/e2e/cli-plugins/dial_test.go (about)

     1  package cliplugins
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/docker/cli/cli-plugins/manager"
     9  	"gotest.tools/v3/assert"
    10  	is "gotest.tools/v3/assert/cmp"
    11  	"gotest.tools/v3/icmd"
    12  )
    13  
    14  func TestCLIPluginDialStdio(t *testing.T) {
    15  	if os.Getenv("DOCKER_CLI_PLUGIN_USE_DIAL_STDIO") == "" {
    16  		t.Skip("skipping plugin dial-stdio test since DOCKER_CLI_PLUGIN_USE_DIAL_STDIO is not set")
    17  	}
    18  
    19  	// Run the helloworld plugin forcing /bin/true as the `system
    20  	// dial-stdio` target. It should be passed all arguments from
    21  	// before the `helloworld` arg, but not the --who=foo which
    22  	// follows. We observe this from the debug level logging from
    23  	// the connhelper stuff.
    24  	helloworld := filepath.Join(os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"), "docker-helloworld")
    25  	cmd := icmd.Command(helloworld, "--config=blah", "--log-level", "debug", "helloworld", "--who=foo")
    26  	res := icmd.RunCmd(cmd, icmd.WithEnv(manager.ReexecEnvvar+"=/bin/true"))
    27  	res.Assert(t, icmd.Success)
    28  	assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --log-level debug system dial-stdio]"`))
    29  	assert.Assert(t, is.Equal(res.Stdout(), "Hello foo!\n"))
    30  }