examples: make examples testable

This commit is contained in:
Ariel Mashraki
2019-12-09 09:05:05 +02:00
parent 754a8c9daa
commit ef7a1ed300
19 changed files with 129 additions and 31 deletions

View File

@@ -9,3 +9,9 @@ B can get its spouse using the `spouse` edge.
```console
go generate ./...
```
### Run Examples
```console
go test
```

View File

@@ -15,20 +15,25 @@ import (
_ "github.com/mattn/go-sqlite3"
)
func main() {
func Example_O2OBidi() {
client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
if err != nil {
log.Fatalf("failed opening connection to sqlite: %v", err)
}
defer client.Close()
ctx := context.Background()
// run the auto migration tool.
// Run the auto migration tool.
if err := client.Schema.Create(ctx); err != nil {
log.Fatalf("failed creating schema resources: %v", err)
}
if err := Do(ctx, client); err != nil {
log.Fatal(err)
}
// Output:
// a8m
// nati
// 2
// nati
}
func Do(ctx context.Context, client *ent.Client) error {