alt/services/worker/internal/storage/postgres/migrate_test.go
toki f762d2abd9 feat: worker persistence layer and socket session updates
- Add worker storage layer with PostgreSQL/sqlc setup
- Add migration files for worker backbone schema
- Add job runner and built-in jobs implementation
- Add Redis key definitions for worker state management
- Archive socket-session-loop milestone (completed/renamed)
- Update roadmap current.md and foundation-alignment phase
- Add socket endpoint integration and runtime smoke tests
- Add infra-check, worker-storage-check, worker-storage-gen CLI tools
- Update API socket server and config
- Add pubspec dependencies and client socket endpoint changes
- Add config tests for API and worker services
2026-05-28 19:05:10 +09:00

81 lines
1.9 KiB
Go

package postgres
import (
"strconv"
"strings"
"testing"
)
func TestMigrationsAreEmbeddedInOrder(t *testing.T) {
entries, err := migrationsFS.ReadDir("migrations")
if err != nil {
t.Fatalf("failed to read migrations directory: %v", err)
}
var upFiles []string
var downFiles []string
for _, entry := range entries {
if entry.IsDir() {
continue
}
name := entry.Name()
if strings.HasSuffix(name, ".up.sql") {
upFiles = append(upFiles, name)
} else if strings.HasSuffix(name, ".down.sql") {
downFiles = append(downFiles, name)
}
}
if len(upFiles) == 0 {
t.Error("expected at least one up migration file, found none")
}
if len(downFiles) == 0 {
t.Error("expected at least one down migration file, found none")
}
if len(upFiles) != len(downFiles) {
t.Errorf("mismatched migration count: %d up files, %d down files", len(upFiles), len(downFiles))
}
// Verify up and down files match and are in numerical order
for i := 0; i < len(upFiles); i++ {
up := upFiles[i]
partsUp := strings.Split(up, "_")
if len(partsUp) < 2 {
t.Errorf("invalid up migration file name: %s", up)
continue
}
versionUp, err := strconv.ParseInt(partsUp[0], 10, 64)
if err != nil {
t.Errorf("failed to parse up version from %s: %v", up, err)
}
if versionUp != int64(i+1) {
t.Errorf("expected version %d for file %s, got %d", i+1, up, versionUp)
}
// Find corresponding down file
var foundDown bool
for _, down := range downFiles {
if strings.Split(down, "_")[0] == partsUp[0] {
foundDown = true
break
}
}
if !foundDown {
t.Errorf("missing corresponding down migration for: %s", up)
}
}
}
func TestMigrationStatementsAreNamed(t *testing.T) {
// Check if migrate.go FS variable is populated
entries, err := migrationsFS.ReadDir("migrations")
if err != nil {
t.Fatalf("failed to read migrations: %v", err)
}
if len(entries) == 0 {
t.Error("migrations FS has no entries")
}
}