Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(schema): test multi-schema #1310

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})
})
}
}
Loading