oceanbase
78 строк · 1.7 Кб
1// Code generated by entc, DO NOT EDIT.
2
3package enttest4
5import (6"context"7
8"github.com/oceanbase/configserver/ent"9// required by schema hooks.10_ "github.com/oceanbase/configserver/ent/runtime"11
12"entgo.io/ent/dialect/sql/schema"13)
14
15type (16// TestingT is the interface that is shared between17// testing.T and testing.B and used by enttest.18TestingT interface {19FailNow()20Error(...interface{})21}22
23// Option configures client creation.24Option func(*options)25
26options struct {27opts []ent.Option28migrateOpts []schema.MigrateOption29}30)
31
32// WithOptions forwards options to client creation.
33func WithOptions(opts ...ent.Option) Option {34return func(o *options) {35o.opts = append(o.opts, opts...)36}37}
38
39// WithMigrateOptions forwards options to auto migration.
40func WithMigrateOptions(opts ...schema.MigrateOption) Option {41return func(o *options) {42o.migrateOpts = append(o.migrateOpts, opts...)43}44}
45
46func newOptions(opts []Option) *options {47o := &options{}48for _, opt := range opts {49opt(o)50}51return o52}
53
54// Open calls ent.Open and auto-run migration.
55func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {56o := newOptions(opts)57c, err := ent.Open(driverName, dataSourceName, o.opts...)58if err != nil {59t.Error(err)60t.FailNow()61}62if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {63t.Error(err)64t.FailNow()65}66return c67}
68
69// NewClient calls ent.NewClient and auto-run migration.
70func NewClient(t TestingT, opts ...Option) *ent.Client {71o := newOptions(opts)72c := ent.NewClient(o.opts...)73if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {74t.Error(err)75t.FailNow()76}77return c78}
79