Skip to content

Commit

Permalink
chore: debug sshserver errors
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Sep 23, 2024
1 parent c0e07dd commit 7512ceb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions testhelper/docker/resource/sshserver/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,33 @@ func Setup(pool *dockertest.Pool, cln resource.Cleaner, opts ...Option) (*Resour
}

var (
buf *bytes.Buffer
timeout = time.After(30 * time.Second)
ticker = time.NewTicker(200 * time.Millisecond)
)
loop:
for {
select {
case <-ticker.C:
buf = bytes.NewBuffer(nil)
stdOut := bytes.NewBuffer(nil)
stdErr := bytes.NewBuffer(nil)

exitCode, err := container.Exec([]string{"cat", "/config/logs/openssh/current"}, dockertest.ExecOptions{
StdOut: buf,
StdOut: stdOut,
StdErr: stdErr,
})
if err != nil {
cln.Log("could not exec into SSH server:", err)
cln.Logf("could not exec into SSH server: %s. \nstdout: \n%s, \nstderr: \n%s", err, stdOut.String(), stdErr.String())
continue
}
if exitCode != 0 {
cln.Log("invalid exit code while exec-ing into SSH server:", exitCode)
cln.Logf("invalid exit code while exec-ing into SSH server: %d. \nstdout: \n%s, \nstderr: \n%s", exitCode, stdOut.String(), stdErr.String())
continue
}
if buf.String() == "" {
if stdOut.String() == "" {
cln.Log("SSH server not ready yet")
continue
}
if !strings.Contains(buf.String(), "Server listening on :: port "+exposedPort) {
if !strings.Contains(stdOut.String(), "Server listening on :: port "+exposedPort) {
cln.Log("SSH server not listening on port yet")
continue
}
Expand Down

0 comments on commit 7512ceb

Please sign in to comment.