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), 0644); 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), 0644); 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)
|
|
}
|
|
}
|