Files
weatherfeeder/internal/sinks/postgres/schema_test.go

43 lines
1.1 KiB
Go
Raw Normal View History

2026-03-16 15:32:46 -05:00
package postgres
import "testing"
2026-03-16 15:32:46 -05:00
func TestWeatherPostgresSchemaShape(t *testing.T) {
s := PostgresSchema()
2026-03-16 15:32:46 -05:00
if s.MapEvent == nil {
t.Fatalf("PostgresSchema().MapEvent is nil")
2026-03-16 15:32:46 -05:00
}
wantTables := map[string]bool{
tableObservations: true,
tableObservationPresentWeather: true,
tableForecasts: true,
tableForecastPeriods: true,
tableForecastDiscussions: true,
tableForecastDiscussionKeyMessages: true,
tableAlertRuns: true,
tableAlerts: true,
tableAlertReferences: true,
2026-03-16 15:32:46 -05:00
}
if len(s.Tables) != len(wantTables) {
t.Fatalf("PostgresSchema().Tables len = %d, want %d", len(s.Tables), len(wantTables))
2026-03-16 15:32:46 -05:00
}
seenIndexes := map[string]bool{}
for _, tbl := range s.Tables {
if !wantTables[tbl.Name] {
t.Fatalf("unexpected table %q in schema", tbl.Name)
}
if tbl.PruneColumn == "" {
t.Fatalf("table %q missing prune column", tbl.Name)
}
for _, idx := range tbl.Indexes {
if seenIndexes[idx.Name] {
t.Fatalf("duplicate index name %q", idx.Name)
}
seenIndexes[idx.Name] = true
}
}
}