Skip to content

Commit

Permalink
Add option to always print server logs
Browse files Browse the repository at this point in the history
Spawned from #68
  • Loading branch information
MadLittleMods committed Jul 16, 2021
1 parent 91b0879 commit 2257ed0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ There is no syntactically pleasing way to do this. Create a separate function wh

This is done using standard Go testing mechanisms, use `t.Logf(...)` which will be logged only if the test fails or if `-v` is set. Note that you will not need to log HTTP requests performed using one of the built in deployment clients as they are already wrapped in loggers. For full HTTP logs, use `COMPLEMENT_DEBUG=1`.


### How do I show the server logs even when the tests pass?

Normally, server logs are only printed when one of the tests fail. To override that behavior to always show server logs, you can use `COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1`.


### How do I skip a test?

Use one of `t.Skipf(...)` or `t.SkipNow()`.
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Complement struct {
BaseImageURI string
BaseImageArgs []string
DebugLoggingEnabled bool
AlwaysPrintServerLogs bool
BestEffort bool
VersionCheckIterations int
KeepBlueprints []string
Expand All @@ -20,6 +21,7 @@ func NewConfigFromEnvVars() *Complement {
cfg.BaseImageURI = os.Getenv("COMPLEMENT_BASE_IMAGE")
cfg.BaseImageArgs = strings.Split(os.Getenv("COMPLEMENT_BASE_IMAGE_ARGS"), " ")
cfg.DebugLoggingEnabled = os.Getenv("COMPLEMENT_DEBUG") == "1"
cfg.AlwaysPrintServerLogs = os.Getenv("COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS") == "1"
cfg.VersionCheckIterations = parseEnvWithDefault("COMPLEMENT_VERSION_CHECK_ITERATIONS", 100)
cfg.KeepBlueprints = strings.Split(os.Getenv("COMPLEMENT_KEEP_BLUEPRINTS"), " ")
if cfg.BaseImageURI == "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/docker/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type HomeserverDeployment struct {
// will print container logs before killing the container.
func (d *Deployment) Destroy(t *testing.T) {
t.Helper()
d.Deployer.Destroy(d, t.Failed())
d.Deployer.Destroy(d, d.Deployer.config.AlwaysPrintServerLogs || t.Failed())
}

// Client returns a CSAPI client targeting the given hsName, using the access token for the given userID.
Expand Down

0 comments on commit 2257ed0

Please sign in to comment.