Skip to content

Commit

Permalink
Add COMPLEMENT_CRYPTO_WRITE_CONTAINER_LOGS to write SS logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 17, 2023
1 parent bac3cb2 commit 044a859
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion internal/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package deploy
import (
"context"
"fmt"
"io"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -34,8 +35,14 @@ func (d *SlidingSyncDeployment) SlidingSyncURL(t *testing.T) string {
return d.slidingSyncURL
}

func (d *SlidingSyncDeployment) Teardown() {
func (d *SlidingSyncDeployment) Teardown(writeLogs bool) {
if d.slidingSync != nil {
if writeLogs {
err := writeContainerLogs(d.slidingSync, "container-sliding-sync.log")
if err != nil {
log.Printf("failed to write sliding sync logs: %s", err)
}
}
if err := d.slidingSync.Terminate(context.Background()); err != nil {
log.Fatalf("failed to stop sliding sync: %s", err)
}
Expand Down Expand Up @@ -148,3 +155,19 @@ func externalURL(t *testing.T, c testcontainers.Container, exposedPort string) s
must.NotError(t, "failed to get mapped port", err)
return fmt.Sprintf("http://%s:%s", host, mappedPort.Port())
}

func writeContainerLogs(container testcontainers.Container, filename string) error {
w, err := os.Create(filename)
if err != nil {
return fmt.Errorf("os.Create: %s", err)
}
reader, err := container.Logs(context.Background())
if err != nil {
return fmt.Errorf("container.Logs: %s", err)
}
_, err = io.Copy(w, reader)
if err != nil {
return fmt.Errorf("io.Copy: %s", err)
}
return nil
}
2 changes: 1 addition & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestMain(m *testing.M) {
complement.TestMainWithCleanup(m, "crypto", func() { // always teardown even if panicking
ssMutex.Lock()
if ssDeployment != nil {
ssDeployment.Teardown()
ssDeployment.Teardown(os.Getenv("COMPLEMENT_CRYPTO_WRITE_CONTAINER_LOGS") == "1")
}
ssMutex.Unlock()
api.WriteJSLogs()
Expand Down

0 comments on commit 044a859

Please sign in to comment.