Skip to content

Commit

Permalink
test(schema): test multi-schema (#1310)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Jun 27, 2024
1 parent d7782c8 commit 4108889
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/misc/multischema/base.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
datasource db {
provider = "sqlite"
url = env("__REPLACE__")
}

generator db {
provider = "go run github.com/steebchen/prisma-client-go"
output = "."
disableGoBinaries = true
package = "db"
previewFeatures = ["prismaSchemaFolder"]
}

model noop {
id String @id @default(cuid()) @map("_id")
}
5 changes: 5 additions & 0 deletions test/misc/multischema/post.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
model Post {
id String @id @default(cuid()) @map("_id")
title String
views Int
}
47 changes: 47 additions & 0 deletions test/misc/multischema/schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//go:generate go run github.com/steebchen/prisma-client-go generate --schema .

package db

import (
"context"
"testing"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
type Func func(t *testing.T, client *PrismaClient, ctx cx)

func TestSchema(t *testing.T) {
t.Parallel()

tests := []struct {
name string
before []string
run Func
}{{
name: "run",
run: func(t *testing.T, client *PrismaClient, ctx cx) {
actual, err := client.Post.FindMany(
Post.ID.Equals("stuff"),
).Exec(ctx)
if err != nil {
t.Fatalf("fail %s", err)
}

massert.Equal(t, 0, len(actual))
},
}}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
test.RunSerial(t, test.Databases, func(t *testing.T, db test.Database, ctx context.Context) {
client := NewClient()
mockDBName := test.Start(t, db, client.Engine, tt.before)
defer test.End(t, db, client.Engine, mockDBName)
tt.run(t, client, context.Background())
})
})
}
}

0 comments on commit 4108889

Please sign in to comment.