From 361573bda0627a31d4e5c9e8a1a2f932e808abe2 Mon Sep 17 00:00:00 2001 From: hmzzrcs Date: Wed, 5 Jul 2023 16:16:08 +0800 Subject: [PATCH 1/2] Update client.go Allow user to send something by cmd.Stdin --- client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index a6a9ffa2..620cc7ba 100644 --- a/client.go +++ b/client.go @@ -557,7 +557,9 @@ func (c *Client) Start() (addr net.Addr, err error) { cmd := c.config.Cmd cmd.Env = append(cmd.Env, os.Environ()...) cmd.Env = append(cmd.Env, env...) - cmd.Stdin = os.Stdin + if cmd.Stdin == nil { + cmd.Stdin = os.Stdin + } cmdStdout, err := cmd.StdoutPipe() if err != nil { From d1c940ef6632b45f7aba03ce8e81d108caf6af29 Mon Sep 17 00:00:00 2001 From: hmzzrcs Date: Wed, 5 Jul 2023 18:52:14 +0800 Subject: [PATCH 2/2] Update client_test.go add test case for stdin --- client_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/client_test.go b/client_test.go index 38dadfe3..f58dc016 100644 --- a/client_test.go +++ b/client_test.go @@ -819,7 +819,34 @@ func TestClient_Stdin(t *testing.T) { t.Fatal("process didn't exit cleanly") } } +func TestClient_StdinBuffer(t *testing.T) { + process := helperProcess("stdin") + process.Stdin = bytes.NewBufferString("hello") + c := NewClient(&ClientConfig{ + Cmd: process, + HandshakeConfig: testHandshake, + Plugins: testPluginMap, + }) + defer c.Kill() + + _, err := c.Start() + if err != nil { + t.Fatalf("error: %s", err) + } + + for { + if c.Exited() { + break + } + + time.Sleep(50 * time.Millisecond) + } + + if !process.ProcessState.Success() { + t.Fatal("process didn't exit cleanly") + } +} func TestClient_SecureConfig(t *testing.T) { // Test failure case secureConfig := &SecureConfig{