mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-28 17:34:24 -06:00
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:
parent
23c0fb7695
commit
02a41a8802
@ -4,10 +4,11 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// private key for mock server
|
// private key for mock server
|
||||||
@ -75,17 +76,27 @@ func newMockLineServer(t *testing.T) string {
|
|||||||
t.Logf("Handshaking error: %v", err)
|
t.Logf("Handshaking error: %v", err)
|
||||||
}
|
}
|
||||||
t.Log("Accepted SSH connection")
|
t.Log("Accepted SSH connection")
|
||||||
|
|
||||||
for newChannel := range chans {
|
for newChannel := range chans {
|
||||||
channel, _, err := newChannel.Accept()
|
channel, requests, err := newChannel.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unable to accept channel.")
|
t.Errorf("Unable to accept channel.")
|
||||||
}
|
}
|
||||||
t.Log("Accepted 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) {
|
go func(newChannel ssh.NewChannel) {
|
||||||
defer channel.Close()
|
|
||||||
conn.OpenChannel(newChannel.ChannelType(), nil)
|
conn.OpenChannel(newChannel.ChannelType(), nil)
|
||||||
}(newChannel)
|
}(newChannel)
|
||||||
|
|
||||||
|
defer channel.Close()
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}()
|
}()
|
||||||
@ -153,5 +164,8 @@ func TestStart(t *testing.T) {
|
|||||||
cmd.Command = "echo foo"
|
cmd.Command = "echo foo"
|
||||||
cmd.Stdout = stdout
|
cmd.Stdout = stdout
|
||||||
|
|
||||||
client.Start(&cmd)
|
err = client.Start(&cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error executing command: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user