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

@@ -8,3 +8,9 @@ Each user can **have many** friends. If user A becomes a friend of B, B is also
```console
go generate ./...
```
### Run Example
```console
go test
```

View File

@@ -15,7 +15,7 @@ import (
_ "github.com/mattn/go-sqlite3"
)
func main() {
func Example_M2MBidi() {
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)
@@ -29,6 +29,10 @@ func main() {
if err := Do(ctx, client); err != nil {
log.Fatal(err)
}
// Output:
// [User(id=1, age=30, name=a8m)]
// [User(id=2, age=28, name=nati)]
// [User(id=1, age=30, name=a8m) User(id=2, age=28, name=nati)]
}
func Do(ctx context.Context, client *ent.Client) error {