From 02a41a8802c4a21a24bb3de24b6082edc89194c4 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 9 Apr 2015 23:40:40 +0200 Subject: [PATCH] Fixing up the communicator tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turned out the tests didn’t work as expected due to some missing config in the `newMockLineServer` and a defer located in the wrong location. All is good again now… --- helper/ssh/communicator_test.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/helper/ssh/communicator_test.go b/helper/ssh/communicator_test.go index 0e80c94151..b713217010 100644 --- a/helper/ssh/communicator_test.go +++ b/helper/ssh/communicator_test.go @@ -4,10 +4,11 @@ package ssh import ( "bytes" - "golang.org/x/crypto/ssh" "fmt" "net" "testing" + + "golang.org/x/crypto/ssh" ) // private key for mock server @@ -75,17 +76,27 @@ func newMockLineServer(t *testing.T) string { t.Logf("Handshaking error: %v", err) } t.Log("Accepted SSH connection") + for newChannel := range chans { - channel, _, err := newChannel.Accept() + channel, requests, err := newChannel.Accept() if err != nil { t.Errorf("Unable to accept channel.") } t.Log("Accepted channel") + go func(in <-chan *ssh.Request) { + for req := range in { + if req.WantReply { + req.Reply(true, nil) + } + } + }(requests) + go func(newChannel ssh.NewChannel) { - defer channel.Close() conn.OpenChannel(newChannel.ChannelType(), nil) }(newChannel) + + defer channel.Close() } conn.Close() }() @@ -153,5 +164,8 @@ func TestStart(t *testing.T) { cmd.Command = "echo foo" cmd.Stdout = stdout - client.Start(&cmd) + err = client.Start(&cmd) + if err != nil { + t.Fatalf("error executing command: %s", err) + } }