feat(backend): add transactional outbox and embedded goose migrations
This commit is contained in:
1 parent
653f3775f8
commit
15e2e50561
40 files changed
+2471
-67
No files matched your search
@@ -3,11 +3,14 @@ package bootstrap
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/config"
|
||||
)
|
||||
|
||||
func TestServeServersGracefullyStopsOnCancellation(t *testing.T) {
|
||||
@@ -67,3 +70,35 @@ func listenForTest(t *testing.T) net.Listener {
|
||||
t.Cleanup(func() { _ = listener.Close() })
|
||||
return listener
|
||||
}
|
||||
|
||||
func TestMigrateDatabaseSkipsWithoutWork(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
settings config.Config
|
||||
}{
|
||||
{name: "disabled", settings: config.Config{DatabaseMigrateOnStart: false, DatabaseURL: "postgres://app@db/app"}},
|
||||
{name: "database not configured", settings: config.Config{DatabaseMigrateOnStart: true}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := migrateDatabase(t.Context(), test.settings, slog.New(slog.DiscardHandler)); err != nil {
|
||||
t.Fatalf("migrateDatabase() error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateDatabaseHidesConnectionStringOnFailure(t *testing.T) {
|
||||
const password = "startup-secret-password"
|
||||
settings := config.Config{
|
||||
DatabaseMigrateOnStart: true,
|
||||
DatabaseURL: "postgres://app:" + password + "@db:not-a-port/app",
|
||||
}
|
||||
err := migrateDatabase(t.Context(), settings, slog.New(slog.DiscardHandler))
|
||||
if err == nil {
|
||||
t.Fatal("migrateDatabase() accepted an invalid DATABASE_URL")
|
||||
}
|
||||
if strings.Contains(err.Error(), password) || strings.Contains(err.Error(), "db:not-a-port") {
|
||||
t.Fatalf("migrateDatabase() error exposes the connection string: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user