Skip to content

Commit 5cc0026

Browse files
committed
Fix tc main setup for oplog tests
1 parent d46e925 commit 5cc0026

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

pbm/oplog/db_tc_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package oplog
33
import (
44
"context"
55
"fmt"
6+
"log"
67
"os"
78
"testing"
89

@@ -17,29 +18,30 @@ var mClient *mongo.Client
1718

1819
func TestMain(m *testing.M) {
1920
ctx := context.Background()
20-
mongodbContainer, err := mongodb.Run(ctx, "perconalab/percona-server-mongodb:7.0")
21+
mongodbContainer, err := mongodb.Run(ctx, "mongo:8")
2122
if err != nil {
22-
fmt.Fprintf(os.Stderr, "error while creating mongo test container: %v", err)
23-
return
23+
log.Fatalf("error while creating mongo test container: %v", err)
2424
}
25-
defer func() {
26-
if err := testcontainers.TerminateContainer(mongodbContainer); err != nil {
27-
fmt.Fprintf(os.Stderr, "failed to terminate container: %s", err)
28-
}
29-
}()
30-
3125
connStr, err := mongodbContainer.ConnectionString(ctx)
3226
if err != nil {
33-
fmt.Fprintf(os.Stderr, "conn string error: %v", err)
34-
return
27+
log.Fatalf("conn string error: %v", err)
3528
}
3629
mClient, err = mongo.Connect(ctx, options.Client().ApplyURI(connStr))
3730
if err != nil {
38-
fmt.Fprintf(os.Stderr, "mongo client connect error: %v", err)
39-
return
31+
log.Fatalf("mongo client connect error: %v", err)
32+
}
33+
34+
code := m.Run()
35+
36+
err = mClient.Disconnect(ctx)
37+
if err != nil {
38+
log.Fatalf("mongo client disconnect error: %v", err)
39+
}
40+
if err := testcontainers.TerminateContainer(mongodbContainer); err != nil {
41+
log.Fatalf("failed to terminate container: %s", err)
4042
}
4143

42-
m.Run()
44+
os.Exit(code)
4345
}
4446

4547
func TestGetUUIDForNSv2(t *testing.T) {

0 commit comments

Comments
 (0)