oceanbase

Форк
0
78 строк · 1.7 Кб
1
// Code generated by entc, DO NOT EDIT.
2

3
package enttest
4

5
import (
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

15
type (
16
	// TestingT is the interface that is shared between
17
	// testing.T and testing.B and used by enttest.
18
	TestingT interface {
19
		FailNow()
20
		Error(...interface{})
21
	}
22

23
	// Option configures client creation.
24
	Option func(*options)
25

26
	options struct {
27
		opts        []ent.Option
28
		migrateOpts []schema.MigrateOption
29
	}
30
)
31

32
// WithOptions forwards options to client creation.
33
func WithOptions(opts ...ent.Option) Option {
34
	return func(o *options) {
35
		o.opts = append(o.opts, opts...)
36
	}
37
}
38

39
// WithMigrateOptions forwards options to auto migration.
40
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
41
	return func(o *options) {
42
		o.migrateOpts = append(o.migrateOpts, opts...)
43
	}
44
}
45

46
func newOptions(opts []Option) *options {
47
	o := &options{}
48
	for _, opt := range opts {
49
		opt(o)
50
	}
51
	return o
52
}
53

54
// Open calls ent.Open and auto-run migration.
55
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
56
	o := newOptions(opts)
57
	c, err := ent.Open(driverName, dataSourceName, o.opts...)
58
	if err != nil {
59
		t.Error(err)
60
		t.FailNow()
61
	}
62
	if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
63
		t.Error(err)
64
		t.FailNow()
65
	}
66
	return c
67
}
68

69
// NewClient calls ent.NewClient and auto-run migration.
70
func NewClient(t TestingT, opts ...Option) *ent.Client {
71
	o := newOptions(opts)
72
	c := ent.NewClient(o.opts...)
73
	if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
74
		t.Error(err)
75
		t.FailNow()
76
	}
77
	return c
78
}
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.