feat(policy): add immutable versioned product policy store
This commit is contained in:
1 parent
0e2a3b02ab
commit
7a5105acc7
30 files changed
+3893
-37
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"lincodex/backend/config"
|
||||
)
|
||||
|
||||
func TestSeedDemoPolicySkipsWithoutStartupMigrations(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
settings config.Config
|
||||
}{
|
||||
// An unreachable address proves that no connection is attempted.
|
||||
{name: "startup migrations disabled", settings: config.Config{DatabaseMigrateOnStart: false, DatabaseURL: "postgres://app@db:not-a-port/app"}},
|
||||
{name: "database not configured", settings: config.Config{DatabaseMigrateOnStart: true}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := seedDemoPolicy(t.Context(), test.settings, slog.New(slog.DiscardHandler)); err != nil {
|
||||
t.Fatalf("seedDemoPolicy() error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedDemoPolicyHidesConnectionStringOnFailure(t *testing.T) {
|
||||
const password = "seed-secret-password"
|
||||
settings := config.Config{
|
||||
DatabaseMigrateOnStart: true,
|
||||
DatabaseURL: "postgres://app:" + password + "@db:not-a-port/app",
|
||||
}
|
||||
err := seedDemoPolicy(t.Context(), settings, slog.New(slog.DiscardHandler))
|
||||
if err == nil {
|
||||
t.Fatal("seedDemoPolicy() accepted an invalid DATABASE_URL")
|
||||
}
|
||||
if strings.Contains(err.Error(), password) || strings.Contains(err.Error(), "db:not-a-port") {
|
||||
t.Fatalf("seedDemoPolicy() error exposes the connection string: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user