29 lines
758 B
Go
29 lines
758 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadDatabaseSupportsSQLDir(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(tempDir, "1_001_create_users.sql"), []byte("CREATE TABLE users (id int);"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(tempDir, "1_002_seed_users.pgsql"), []byte("INSERT INTO users (id) VALUES (1);"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
db, err := readDatabase("sqldir", tempDir, "", "source")
|
|
if err != nil {
|
|
t.Fatalf("readDatabase failed: %v", err)
|
|
}
|
|
if len(db.Schemas) != 1 {
|
|
t.Fatalf("expected 1 schema, got %d", len(db.Schemas))
|
|
}
|
|
if got := len(db.Schemas[0].Scripts); got != 2 {
|
|
t.Fatalf("expected 2 scripts, got %d", got)
|
|
}
|
|
}
|