feat(store): goose-миграции схемы + seed default tenant, тест на testcontainers
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
func TestMigrateCreatesTablesAndSeed(t *testing.T) {
|
||||
dsn := startPostgres(t)
|
||||
ctx := context.Background()
|
||||
pool, err := pgxpool.New(ctx, dsn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
// таблицы существуют
|
||||
for _, table := range []string{"users", "projects", "provider_accounts", "templates", "domains", "check_runs"} {
|
||||
var exists bool
|
||||
err := pool.QueryRow(ctx,
|
||||
`SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name=$1)`, table).Scan(&exists)
|
||||
if err != nil || !exists {
|
||||
t.Fatalf("table %s missing (err=%v)", table, err)
|
||||
}
|
||||
}
|
||||
// seed default project присутствует
|
||||
var name string
|
||||
err = pool.QueryRow(ctx, `SELECT name FROM projects WHERE id='00000000-0000-0000-0000-000000000002'`).Scan(&name)
|
||||
if err != nil || name != "default" {
|
||||
t.Fatalf("seed project missing: name=%q err=%v", name, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user