mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
capture container logs prior to removing container if the test is failed (#27332)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user