mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-27 02:24:30 +01:00
765aba2c1c
propagate context from all the API calls and log request ID, account ID and peer ID --------- Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
//go:build !ios
|
|
// +build !ios
|
|
|
|
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"time"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/testcontainers/testcontainers-go"
|
|
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
|
"github.com/testcontainers/testcontainers-go/wait"
|
|
)
|
|
|
|
func CreatePGDB() (func(), error) {
|
|
ctx := context.Background()
|
|
c, err := postgres.RunContainer(ctx,
|
|
testcontainers.WithImage("postgres:alpine"),
|
|
postgres.WithDatabase("test"),
|
|
postgres.WithUsername("postgres"),
|
|
postgres.WithPassword("postgres"),
|
|
testcontainers.WithWaitStrategy(
|
|
wait.ForLog("database system is ready to accept connections").
|
|
WithOccurrence(2).WithStartupTimeout(15*time.Second)),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cleanup := func() {
|
|
timeout := 10 * time.Second
|
|
err = c.Stop(ctx, &timeout)
|
|
if err != nil {
|
|
log.WithContext(ctx).Warnf("failed to stop container: %s", err)
|
|
}
|
|
}
|
|
|
|
talksConn, err := c.ConnectionString(ctx)
|
|
if err != nil {
|
|
return cleanup, err
|
|
}
|
|
return cleanup, os.Setenv("NETBIRD_STORE_ENGINE_POSTGRES_DSN", talksConn)
|
|
}
|