* Add lint/format checks to the Gitea release workflow and Makefile (targets: vet, fmt, fmt-check, staticcheck, govulncheck, check) * Switch .golangci.json formatter from gofmt to gofumpt (extra.group-params) * Bump golang.org/x/text 0.37.0 -> 0.39.0 for GO-2026-5970; re-vendor * Fix staticcheck S1011 in pkg/diff; drop unused pgsql writer helpers * Fix gocritic unnamedResult (pkg/diff) and rangeValCopy (pkg/pgsql) * Apply gofumpt + goimports formatting across the tree
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package prisma
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/readers"
|
|
)
|
|
|
|
func TestReadDatabase_Prisma7GeneratorSetsSourceFormat(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tmpDir := t.TempDir()
|
|
schemaPath := filepath.Join(tmpDir, "schema.prisma")
|
|
|
|
content := `datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client"
|
|
output = "./generated"
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
}`
|
|
|
|
if err := os.WriteFile(schemaPath, []byte(content), 0o644); err != nil {
|
|
t.Fatalf("failed to write schema: %v", err)
|
|
}
|
|
|
|
reader := NewReader(&readers.ReaderOptions{FilePath: schemaPath})
|
|
db, err := reader.ReadDatabase()
|
|
if err != nil {
|
|
t.Fatalf("ReadDatabase() failed: %v", err)
|
|
}
|
|
|
|
if db.SourceFormat != "prisma7" {
|
|
t.Fatalf("expected SourceFormat prisma7, got %q", db.SourceFormat)
|
|
}
|
|
}
|
|
|
|
func TestReadDatabase_Prisma7FlagSetsSourceFormatWithoutGenerator(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tmpDir := t.TempDir()
|
|
schemaPath := filepath.Join(tmpDir, "schema.prisma")
|
|
|
|
content := `datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
}`
|
|
|
|
if err := os.WriteFile(schemaPath, []byte(content), 0o644); err != nil {
|
|
t.Fatalf("failed to write schema: %v", err)
|
|
}
|
|
|
|
reader := NewReader(&readers.ReaderOptions{
|
|
FilePath: schemaPath,
|
|
Prisma7: true,
|
|
})
|
|
db, err := reader.ReadDatabase()
|
|
if err != nil {
|
|
t.Fatalf("ReadDatabase() failed: %v", err)
|
|
}
|
|
|
|
if db.SourceFormat != "prisma7" {
|
|
t.Fatalf("expected SourceFormat prisma7 from flag, got %q", db.SourceFormat)
|
|
}
|
|
}
|