Idk why, but testcontainers is borked on Discovery

This commit is contained in:
Melody Becker 2025-03-31 08:07:24 +02:00
parent 7d385e48de
commit 8ba5e98c50
No known key found for this signature in database

View file

@ -1,19 +1,15 @@
package main package main
import ( import (
"context"
"flag" "flag"
"time"
"git.mstar.dev/mstar/goutils/other" "git.mstar.dev/mstar/goutils/other"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/testcontainers/testcontainers-go"
postgresContainer "github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/wait"
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
"gorm.io/gen" "gorm.io/gen"
"gorm.io/gorm" "gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/shared" "git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage-new/models" "git.mstar.dev/mstar/linstrom/storage-new/models"
) )
@ -36,36 +32,36 @@ func main() {
other.SetupFlags() other.SetupFlags()
flag.Parse() flag.Parse()
other.ConfigureLogging(nil) other.ConfigureLogging(nil)
// config.ReadAndWriteToGlobal(*shared.FlagConfigFile) config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
// Set up a temporary postgres container for gorm-gen to do its thing // Set up a temporary postgres container for gorm-gen to do its thing
log.Info().Msg("Starting temporary postgres container") // log.Info().Msg("Starting temporary postgres container")
pgContainer, err := postgresContainer.Run( // pgContainer, err := postgresContainer.Run(
context.Background(), // context.Background(),
"postgres:16.4-alpine", // "postgres:16.4-alpine",
postgresContainer.WithDatabase(dbName), // postgresContainer.WithDatabase(dbName),
postgresContainer.WithUsername(dbUser), // postgresContainer.WithUsername(dbUser),
postgresContainer.WithPassword(dbPass), // postgresContainer.WithPassword(dbPass),
testcontainers.WithWaitStrategyAndDeadline( // testcontainers.WithWaitStrategyAndDeadline(
time.Minute, // time.Minute,
wait.ForLog("database system is ready to accept connections"). // wait.ForLog("database system is ready to accept connections").
WithOccurrence(2). // WithOccurrence(2).
WithStartupTimeout(time.Second*5), // WithStartupTimeout(time.Second*5),
), // ),
) // )
if err != nil { // if err != nil {
log.Fatal().Err(err).Msg("Failed to setup temporary postgres container") // log.Fatal().Err(err).Msg("Failed to setup temporary postgres container")
} // }
log.Info().Msg("Temporary postgres container started") // log.Info().Msg("Temporary postgres container started")
defer func() { // defer func() {
if err := testcontainers.TerminateContainer(pgContainer); err != nil { // if err := testcontainers.TerminateContainer(pgContainer); err != nil {
log.Fatal().Err(err).Msg("Failed to terminate temporary postgres container") // log.Fatal().Err(err).Msg("Failed to terminate temporary postgres container")
} // }
log.Info().Msg("Temporary postgres container stopped") // log.Info().Msg("Temporary postgres container stopped")
}() // }()
db, err := gorm.Open( db, err := gorm.Open(
// postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()), postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),
postgres.Open(pgContainer.MustConnectionString(context.Background())), // postgres.Open(pgContainer.MustConnectionString(context.Background())),
&gorm.Config{ &gorm.Config{
PrepareStmt: false, PrepareStmt: false,
Logger: shared.NewGormLogger(log.Logger), Logger: shared.NewGormLogger(log.Logger),