From 2ab7d4569771ea312620b1c5d409fcccb126e82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wa=C5=9B?= Date: Mon, 29 Apr 2024 17:10:36 +0200 Subject: [PATCH] Dump container logs when it fails to become ready --- go.mod | 2 ++ go.sum | 4 ++++ trino/integration_test.go | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ce579b8..a87d1a3 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/trinodb/trino-go-client go 1.21 require ( + github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26 github.com/golang-jwt/jwt/v4 v4.5.0 github.com/ory/dockertest/v3 v3.10.0 github.com/stretchr/testify v1.9.0 @@ -14,6 +15,7 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect + github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/containerd/continuity v0.4.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index e385be0..a26c888 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= +github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:pzStYMLAXM7CNQjS/Wn+zK9MUxDhSUNfVvnHsyQyjs0= +github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:ilK+u7u1HoqaDk0mjhh27QJB7PyWMreGffEvOCoEKiY= +github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:3YVZUqkoev4mL+aCwVOSWV4M7pN+NURHL38Z2zq5JKA= +github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:ymXt5bw5uSNu4jveerFxE0vNYxF8ncqbptntMaFMg3k= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8= diff --git a/trino/integration_test.go b/trino/integration_test.go index aa41c50..ecd8e08 100644 --- a/trino/integration_test.go +++ b/trino/integration_test.go @@ -15,6 +15,7 @@ package trino import ( + "bytes" "context" "crypto/rand" "crypto/rsa" @@ -36,8 +37,10 @@ import ( "testing" "time" + "github.com/ahmetb/dlog" "github.com/golang-jwt/jwt/v4" dt "github.com/ory/dockertest/v3" + docker "github.com/ory/dockertest/v3/docker" ) var ( @@ -121,7 +124,8 @@ func TestMain(m *testing.M) { } return nil }); err != nil { - log.Fatalf("Timed out waiting for container to get ready: %s", err) + logs := getLogs(resource.Container.ID) + log.Fatalf("Timed out waiting for container to get ready: %s\nContainer logs:\n%s", err, logs) } *integrationServerFlag = "http://test@localhost:" + resource.GetPort("8080/tcp") tlsServer = "https://test@localhost:" + resource.GetPort("8443/tcp") @@ -242,6 +246,20 @@ func getTLSConfig(dir string) (*tls.Config, error) { }, nil } +func getLogs(id string) []byte { + var buf bytes.Buffer + pool.Client.Logs(docker.LogsOptions{ + Container: id, + OutputStream: &buf, + ErrorStream: &buf, + Stdout: true, + Stderr: true, + RawTerminal: true, + }) + logs, _ := io.ReadAll(dlog.NewReader(&buf)) + return logs +} + // integrationOpen opens a connection to the integration test server. func integrationOpen(t *testing.T, dsn ...string) *sql.DB { if testing.Short() {