123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // Code generated by entc, DO NOT EDIT.
- package enttest
- import (
- "context"
- "code.osinet.fr/fgm/go__ent_demo/ent"
- // required by schema hooks.
- _ "code.osinet.fr/fgm/go__ent_demo/ent/runtime"
- "entgo.io/ent/dialect/sql/schema"
- )
- type (
- // TestingT is the interface that is shared between
- // testing.T and testing.B and used by enttest.
- TestingT interface {
- FailNow()
- Error(...interface{})
- }
- // Option configures client creation.
- Option func(*options)
- options struct {
- opts []ent.Option
- migrateOpts []schema.MigrateOption
- }
- )
- // WithOptions forwards options to client creation.
- func WithOptions(opts ...ent.Option) Option {
- return func(o *options) {
- o.opts = append(o.opts, opts...)
- }
- }
- // WithMigrateOptions forwards options to auto migration.
- func WithMigrateOptions(opts ...schema.MigrateOption) Option {
- return func(o *options) {
- o.migrateOpts = append(o.migrateOpts, opts...)
- }
- }
- func newOptions(opts []Option) *options {
- o := &options{}
- for _, opt := range opts {
- opt(o)
- }
- return o
- }
- // Open calls ent.Open and auto-run migration.
- func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
- o := newOptions(opts)
- c, err := ent.Open(driverName, dataSourceName, o.opts...)
- if err != nil {
- t.Error(err)
- t.FailNow()
- }
- if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
- t.Error(err)
- t.FailNow()
- }
- return c
- }
- // NewClient calls ent.NewClient and auto-run migration.
- func NewClient(t TestingT, opts ...Option) *ent.Client {
- o := newOptions(opts)
- c := ent.NewClient(o.opts...)
- if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
- t.Error(err)
- t.FailNow()
- }
- return c
- }
|