Files
archie/internal/platform/pg/pg_test.go
T

44 lines
1.2 KiB
Go

package pg
import (
"slices"
"testing"
)
func TestEmbeddedMigrationVersions(t *testing.T) {
versions, err := embeddedMigrationVersions()
if err != nil {
t.Fatalf("embeddedMigrationVersions: %v", err)
}
if len(versions) == 0 {
t.Fatal("expected at least one embedded migration")
}
if !slices.IsSorted(versions) {
t.Fatalf("versions not sorted: %v", versions)
}
}
// TestMissingMigrations guards schema verification for DML-only serving pods.
func TestMissingMigrations(t *testing.T) {
embedded := []int64{1, 2, 3}
tests := []struct {
name string
applied []int64
want []int64
}{
{name: "up to date", applied: []int64{1, 2, 3}, want: nil},
{name: "ahead with extra history", applied: []int64{1, 2, 3, 4}, want: nil},
{name: "pending tail migration", applied: []int64{1, 2}, want: []int64{3}},
{name: "missing middle migration", applied: []int64{1, 3}, want: []int64{2}},
{name: "empty database", applied: nil, want: []int64{1, 2, 3}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := missingMigrations(embedded, tc.applied)
if !slices.Equal(got, tc.want) {
t.Fatalf("missingMigrations(%v, %v) = %v, want %v", embedded, tc.applied, got, tc.want)
}
})
}
}