mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
test(integration): surface container logs on failed startup
This commit is contained in:
@@ -133,16 +133,30 @@ func startGotenbergContainer(ctx context.Context, env map[string]string) (*testc
|
|||||||
Logger: &noopLogger{},
|
Logger: &noopLogger{},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("start new Gotenberg container: %w", err)
|
||||||
|
|
||||||
|
// A failed start (for example the process exiting before the health
|
||||||
|
// check passes) only reports an opaque exit code. testcontainers
|
||||||
|
// still returns the container on this path, so attach its logs to
|
||||||
|
// surface the actual crash reason in CI.
|
||||||
|
if c != nil {
|
||||||
|
if logs, errLogs := containerLogEntries(ctx, c); errLogs == nil && logs != "" {
|
||||||
|
err = fmt.Errorf("%w\ncontainer logs:\n%s", err, logs)
|
||||||
|
}
|
||||||
|
if errTerminate := c.Terminate(ctx, testcontainers.StopTimeout(0)); errTerminate != nil {
|
||||||
|
err = fmt.Errorf("%w (also failed to terminate container: %v)", err, errTerminate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The network is already created. The scenario teardown only
|
// The network is already created. The scenario teardown only
|
||||||
// removes networks it knows about, and the caller discards n on
|
// removes networks it knows about, and the caller discards n on
|
||||||
// error, so remove it here to avoid leaking a subnet on every
|
// error, so remove it here to avoid leaking a subnet on every
|
||||||
// failed start. Leaked networks accumulate until Docker's address
|
// failed start. Leaked networks accumulate until Docker's address
|
||||||
// pools are fully subnetted and all later scenarios fail.
|
// pools are fully subnetted and all later scenarios fail.
|
||||||
if errRemove := n.Remove(ctx); errRemove != nil {
|
if errRemove := n.Remove(ctx); errRemove != nil {
|
||||||
err = fmt.Errorf("start new Gotenberg container: %w (also failed to remove network: %v)", err, errRemove)
|
err = fmt.Errorf("%w (also failed to remove network: %v)", err, errRemove)
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("start new Gotenberg container: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user