Skip to content

Commit

Permalink
send timeout message to errChan instead of stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Jun 15, 2021
1 parent 84918ec commit d52fc63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions easyssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout ...time.Duration) (<-
go func(stdoutScanner, stderrScanner *bufio.Scanner, stdoutChan, stderrChan chan string, doneChan chan bool, errChan chan error) {
defer close(doneChan)
defer close(errChan)
defer close(stderrChan)
defer client.Close()
defer session.Close()

Expand All @@ -320,6 +319,7 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout ...time.Duration) (<-
}()

go func() {
defer close(stderrChan)
for stderrScanner.Scan() {
stderrChan <- stderrScanner.Text()
}
Expand All @@ -337,8 +337,7 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout ...time.Duration) (<-
errChan <- session.Wait()
doneChan <- true
case <-timeoutChan:
stderrChan <- "Run Command Timeout!"
errChan <- nil
errChan <- fmt.Errorf("Run Command Timeout")
doneChan <- false
}
}(stdoutScanner, stderrScanner, stdoutChan, stderrChan, doneChan, errChan)
Expand Down
5 changes: 3 additions & 2 deletions easyssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ func TestRunCommand(t *testing.T) {
// error message: Run Command Timeout
outStr, errStr, isTimeout, err = ssh.Run("sleep 2", 1*time.Second)
assert.Equal(t, "", outStr)
assert.Equal(t, "Run Command Timeout!\n", errStr)
assert.Equal(t, "", errStr)
assert.False(t, isTimeout)
assert.NoError(t, err)
assert.Error(t, err)
assert.Equal(t, "Run Command Timeout", err.Error())

// test exit code
outStr, errStr, isTimeout, err = ssh.Run("exit 1")
Expand Down

0 comments on commit d52fc63

Please sign in to comment.