88 "log"
99 "net"
1010 "strings"
11+ "time"
1112)
1213
1314var _ Executor = (* SSHExecutor )(nil )
@@ -49,7 +50,7 @@ func NewSSHExecutor(host string, user string, opts ...func(e *SSHExecutor)) Exec
4950}
5051
5152// Execute executes a command on a remote host viá SSH
52- func (e SSHExecutor ) Execute (test TestCase ) TestResult {
53+ func (e SSHExecutor ) Execute (test TestCase ) ( TestResult , error ) {
5354 if test .Command .InheritEnv {
5455 panic ("Inherit env is not supported viá SSH" )
5556 }
@@ -72,19 +73,20 @@ func (e SSHExecutor) Execute(test TestCase) TestResult {
7273 HostKeyCallback : func (hostname string , remote net.Addr , key ssh.PublicKey ) error {
7374 return nil
7475 },
76+ Timeout : 10 * time .Second ,
7577 }
7678
7779 // create ssh connection
7880 conn , err := ssh .Dial ("tcp" , e .Host , sshConf )
7981 if err != nil {
80- log . Fatal ( err )
82+ return TestResult {}, fmt . Errorf ( "Failed to connect to ssh %w" , err )
8183 }
8284
8385 // start session
8486 session , err := conn .NewSession ()
8587 defer session .Close ()
8688 if err != nil {
87- log . Fatal ( err )
89+ return TestResult {}, fmt . Errorf ( "Failed to create a new ssh session %w" , err )
8890 }
8991
9092 var stdoutBuffer bytes.Buffer
@@ -96,11 +98,11 @@ func (e SSHExecutor) Execute(test TestCase) TestResult {
9698 err := session .Setenv (k , v )
9799 if err != nil {
98100 test .Result = CommandResult {
99- Error : fmt .Errorf ("Failed setting env variables, maybe ssh server is configured to only accept LC_ prefixed env variables. Error: %s " , err ),
101+ Error : fmt .Errorf ("Failed setting env variables, maybe ssh server is configured to only accept LC_ prefixed env variables. %w " , err ),
100102 }
101103 return TestResult {
102104 TestCase : test ,
103- }
105+ }, nil
104106 }
105107 }
106108
@@ -125,7 +127,7 @@ func (e SSHExecutor) Execute(test TestCase) TestResult {
125127
126128 return TestResult {
127129 TestCase : test ,
128- }
130+ }, nil
129131 }
130132
131133 test .Result = CommandResult {
@@ -138,7 +140,7 @@ func (e SSHExecutor) Execute(test TestCase) TestResult {
138140 log .Println ("title: '" + test .Title + "'" , " Stdout: " , test .Result .Stdout )
139141 log .Println ("title: '" + test .Title + "'" , " Stderr: " , test .Result .Stderr )
140142
141- return Validate (test )
143+ return Validate (test ), nil
142144}
143145
144146func (e SSHExecutor ) createSigner () ssh.Signer {
0 commit comments