84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
//go:build integration
|
|
|
|
package postgresadmin
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"proxy-pool/internal/domain/adminstate"
|
|
"proxy-pool/internal/domain/adminstate/contracttest"
|
|
)
|
|
|
|
func TestPostgresAdminStateContract(t *testing.T) {
|
|
contracttest.Run(t, func(t *testing.T) adminstate.Store {
|
|
return newPostgresTestFixture(t).Store
|
|
})
|
|
}
|
|
|
|
func TestMigrationsAreIdempotentAndBounded(t *testing.T) {
|
|
fixture := newPostgresTestFixture(t)
|
|
if err := ApplyMigrations(t.Context(), fixture.Pool); err != nil {
|
|
t.Fatalf("ApplyMigrations(second run): %v", err)
|
|
}
|
|
|
|
rows, err := fixture.Pool.Query(context.Background(), `
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = $1 AND table_type = 'BASE TABLE'
|
|
ORDER BY table_name`, fixture.Schema)
|
|
if err != nil {
|
|
t.Fatalf("query migrated tables: %v", err)
|
|
}
|
|
defer rows.Close()
|
|
tables := make([]string, 0, 6)
|
|
for rows.Next() {
|
|
var name string
|
|
if err := rows.Scan(&name); err != nil {
|
|
t.Fatalf("scan migrated table: %v", err)
|
|
}
|
|
tables = append(tables, name)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
t.Fatalf("iterate migrated tables: %v", err)
|
|
}
|
|
want := []string{
|
|
"admin_audit_log",
|
|
"admin_outbox",
|
|
"config_revisions",
|
|
"control_revisions",
|
|
"routing_admin_state",
|
|
"upstream_admin_state",
|
|
}
|
|
if !slices.Equal(tables, want) {
|
|
t.Fatalf("migrated tables = %v, want %v", tables, want)
|
|
}
|
|
|
|
columnRows, err := fixture.Pool.Query(context.Background(), `
|
|
SELECT table_name, column_name
|
|
FROM information_schema.columns
|
|
WHERE table_schema = $1`, fixture.Schema)
|
|
if err != nil {
|
|
t.Fatalf("query migrated columns: %v", err)
|
|
}
|
|
defer columnRows.Close()
|
|
for columnRows.Next() {
|
|
var table string
|
|
var column string
|
|
if err := columnRows.Scan(&table, &column); err != nil {
|
|
t.Fatalf("scan migrated column: %v", err)
|
|
}
|
|
qualified := strings.ToLower(table + "." + column)
|
|
for _, forbidden := range []string{"proxy", "credential", "extraction", "worker_owner", "idempotency"} {
|
|
if strings.Contains(qualified, forbidden) {
|
|
t.Fatalf("PostgreSQL management boundary contains forbidden column %s", qualified)
|
|
}
|
|
}
|
|
}
|
|
if err := columnRows.Err(); err != nil {
|
|
t.Fatalf("iterate migrated columns: %v", err)
|
|
}
|
|
}
|