snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 22:12:36 +05:00
commit 4b3ad0b611
2680 changed files with 719472 additions and 0 deletions

39
doc/md/testing.md Normal file
View File

@@ -0,0 +1,39 @@
---
id: testing
title: Testing
---
If you're using `ent.Client` in your unit-tests, you can use the generated `enttest`
package for creating a client and auto-running the schema migration as follows:
```go
package main
import (
"testing"
"<project>/ent/enttest"
_ "github.com/mattn/go-sqlite3"
)
func TestXXX(t *testing.T) {
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&_fk=1")
defer client.Close()
// ...
}
```
In order to pass functional options to `Open`, use `enttest.Option`:
```go
func TestXXX(t *testing.T) {
opts := []enttest.Option{
enttest.WithOptions(ent.Log(t.Log)),
enttest.WithMigrateOptions(migrate.WithGlobalUniqueID(true)),
}
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&_fk=1", opts...)
defer client.Close()
// ...
}
```