mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Add a core test logger to help capture the MSSQL container output (#28472)
* Add a core test logger to help capture the MSSQL container output - I believe the if t.Failed prevents the logging of the container logging as when executed the test isn't considered failed yet. - Use a test core logger so that we can capture the container output all the time and get it from the captured log files when the test fails * bump image tag to 2022-latest --------- Co-authored-by: JM Faircloth <jmfaircloth@hashicorp.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
|
||||
"github.com/hashicorp/vault/sdk/helper/docker"
|
||||
)
|
||||
|
||||
@@ -32,6 +33,8 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
|
||||
return func() {}, os.Getenv("MSSQL_URL")
|
||||
}
|
||||
|
||||
logger := corehelpers.NewTestLogger(t)
|
||||
|
||||
var err error
|
||||
for i := 0; i < numRetries; i++ {
|
||||
var svc *docker.Service
|
||||
@@ -39,17 +42,15 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
|
||||
runner, err = docker.NewServiceRunner(docker.RunOptions{
|
||||
ContainerName: "sqlserver",
|
||||
ImageRepo: "mcr.microsoft.com/mssql/server",
|
||||
ImageTag: "2017-latest-ubuntu",
|
||||
ImageTag: "2022-latest",
|
||||
Env: []string{"ACCEPT_EULA=Y", "SA_PASSWORD=" + mssqlPassword},
|
||||
Ports: []string{"1433/tcp"},
|
||||
LogConsumer: func(s string) {
|
||||
if t.Failed() {
|
||||
t.Logf("container logs: %s", s)
|
||||
}
|
||||
logger.Info(s)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Logf("Could not start docker MSSQL: %v", err)
|
||||
logger.Error("failed creating new service runner", "error", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -57,9 +58,11 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
|
||||
if err == nil {
|
||||
return svc.Cleanup, svc.Config.URL().String()
|
||||
}
|
||||
|
||||
logger.Error("failed starting service", "error", err.Error())
|
||||
}
|
||||
|
||||
t.Fatalf("Could not start docker MSSQL: %v", err)
|
||||
t.Fatalf("Could not start docker MSSQL last error: %v", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user