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 707881d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions testhelper/docker/resource/sshserver/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,38 @@ 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,
})
logs := func() string {
stream := bytes.NewBuffer(nil)
_ = pool.Client.Logs(dc.LogsOptions{Container: container.Container.ID, OutputStream: stream, ErrorStream: stream})
return stream.String()
}
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\nlogs:\n%s", err, stdOut.String(), stdErr.String(), logs())
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\nlogs:\n%s", exitCode, stdOut.String(), stdErr.String(), logs())
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 707881d

Please sign in to comment.