capture container logs prior to removing container if the test is failed (#27332)

This commit is contained in:
Marc Boudreau
2024-06-04 11:30:42 -04:00
committed by GitHub
parent e99e8870ec
commit 47b7e9d303

View File

@@ -4,6 +4,7 @@
package ldap
import (
"bytes"
"context"
"fmt"
"runtime"
@@ -22,12 +23,16 @@ func PrepareTestContainer(t *testing.T, version string) (cleanup func(), cfg *ld
t.Skip("Skipping, as this image is not supported on ARM architectures")
}
logsWriter := bytes.NewBuffer([]byte{})
runner, err := docker.NewServiceRunner(docker.RunOptions{
ImageRepo: "ghcr.io/rroemhild/docker-test-openldap",
ImageTag: version,
ContainerName: "ldap",
Ports: []string{"10389/tcp"},
// Env: []string{"LDAP_DEBUG_LEVEL=384"},
LogStderr: logsWriter,
LogStdout: logsWriter,
})
if err != nil {
t.Fatalf("could not start local LDAP docker container: %s", err)
@@ -66,5 +71,10 @@ func PrepareTestContainer(t *testing.T, version string) (cleanup func(), cfg *ld
t.Fatalf("could not start local LDAP docker container: %s", err)
}
return svc.Cleanup, cfg
return func() {
if t.Failed() {
t.Log(logsWriter.String())
}
svc.Cleanup()
}, cfg
}