Fixing up the communicator tests

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…
This commit is contained in:
Sander van Harmelen 2015-04-09 23:40:40 +02:00
parent 23c0fb7695
commit 02a41a8802
1 changed files with 18 additions and 4 deletions

View File

@ -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)
}
}