Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container logs to integration test #96

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const (
ECDSA_KEYS_DIR = "../keys/ecdsa"
)

type TestLogConsumer struct {
t *testing.T
containerName string
}

func (lc *TestLogConsumer) Accept(l testcontainers.Log) {
lc.t.Logf("[%s] %s", lc.containerName, string(l.Content))
}

func TestIntegration(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 250*time.Second)
setup := setupTestEnv(t, ctx)
Expand Down Expand Up @@ -466,6 +475,8 @@ func startAnvilTestContainer(t *testing.T, ctx context.Context, name, exposedPor
panic(err)
}

logConsumer := &TestLogConsumer{t: t, containerName: fmt.Sprintf("anvil %s", chainId)}

req := testcontainers.ContainerRequest{
Image: "ghcr.io/foundry-rs/foundry:latest",
Name: name,
Expand Down Expand Up @@ -531,6 +542,12 @@ func startAnvilTestContainer(t *testing.T, ctx context.Context, name, exposedPor
t.Fatalf("Anvil chainId is not the expected: expected %s, got %s", expectedChainId.String(), fetchedChainId.String())
}

anvilC.FollowOutput(logConsumer)
err = anvilC.StartLogProducer(ctx)
if err != nil {
t.Fatalf("Failed to start log producer: %s", err.Error())
}

anvil := &utils.AnvilInstance{
Container: anvilC,
HttpClient: httpClient,
Expand Down Expand Up @@ -653,6 +670,8 @@ func startIndexer(t *testing.T, ctx context.Context, name string, rollupAnvils [
rollupArgs = append(rollupArgs, "--rollup-ids", rollupAnvil.ChainID.String())
}

logConsumer := &TestLogConsumer{t: t, containerName: "indexer"}

req := testcontainers.ContainerRequest{
Image: "near-sffl-indexer",
Name: name,
Expand All @@ -668,6 +687,15 @@ func startIndexer(t *testing.T, ctx context.Context, name string, rollupAnvils [
}

indexerContainer, err := testcontainers.GenericContainer(ctx, genericReq)
if err != nil {
t.Fatalf("Failed to start indexer container: %s", err.Error())
}

indexerContainer.FollowOutput(logConsumer)
err = indexerContainer.StartLogProducer(ctx)
if err != nil {
t.Fatalf("Failed to start log producer: %s", err.Error())
}

if err != nil {
t.Fatalf("Error starting indexer container: %s", err.Error())
Expand Down Expand Up @@ -715,7 +743,9 @@ func setupNearDa(t *testing.T, ctx context.Context, indexerContainer testcontain
t.Fatalf("Error creating NEAR DA account: %s", err.Error())
}

relayer, err := utils.StartRelayer(t, ctx, accountId, indexerContainerIp, rollupAnvil)
logConsumer := &TestLogConsumer{t: t, containerName: fmt.Sprintf("relayer %s", rollupAnvil.ChainID.String())}

relayer, err := utils.StartRelayer(t, ctx, accountId, indexerContainerIp, rollupAnvil, logConsumer)
if err != nil {
t.Fatalf("Error creating realayer: #%s", err.Error())
}
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/utils/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func compileContainerConfig(ctx context.Context, daAccountId, keyPath, indexerIp
}, nil
}

func StartRelayer(t *testing.T, ctx context.Context, daAccountId, indexerContainerIp string, anvil *AnvilInstance) (testcontainers.Container, error) {
func StartRelayer(t *testing.T, ctx context.Context, daAccountId, indexerContainerIp string, anvil *AnvilInstance, logConsumer testcontainers.LogConsumer) (testcontainers.Container, error) {
usr, err := user.Current()
if err != nil {
t.Fatalf("Couldn't get current user: #%s", err.Error())
Expand Down Expand Up @@ -136,10 +136,16 @@ func StartRelayer(t *testing.T, ctx context.Context, daAccountId, indexerContain
Started: true,
}

indexerContainer, err := testcontainers.GenericContainer(ctx, genericReq)
relayerContainer, err := testcontainers.GenericContainer(ctx, genericReq)
if err != nil {
return nil, err
}

return indexerContainer, nil
relayerContainer.FollowOutput(logConsumer)
err = relayerContainer.StartLogProducer(ctx)
if err != nil {
t.Fatalf("Failed to start log producer: %s", err.Error())
}

return relayerContainer, nil
}
Loading