Skip to content

Commit

Permalink
Merge pull request #1469 from svanharmelen/b-communicator-tests
Browse files Browse the repository at this point in the history
Fixing up the communicator tests
  • Loading branch information
Sander van Harmelen committed Apr 9, 2015
2 parents 797bf5f + 02a41a8 commit d90b3aa
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions helper/ssh/communicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}()
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d90b3aa

Please sign in to comment.