diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index ade6d9e1a..7d41c042d 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -38,6 +38,7 @@ // template/dialect/sql/tx.tmpl // template/dialect/sql/update.tmpl // template/ent.tmpl +// template/enttest.tmpl // template/header.tmpl // template/hook.tmpl // template/import.tmpl @@ -885,6 +886,26 @@ func templateEntTmpl() (*asset, error) { return a, nil } +var _templateEnttestTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd4\x55\x4d\x8f\xdb\x36\x13\x3e\x93\xbf\x62\x5e\x61\xf1\x42\x5e\x78\xa9\x34\xb7\xa6\xd8\x43\x62\x6c\x80\x00\xcd\x6e\x81\x5d\xa0\x87\x20\x08\x68\x6a\x24\x11\x96\x49\x85\x1c\xc5\x59\x08\xfa\xef\x05\xa9\x0f\xcb\x76\x36\x2d\xd0\x53\x6f\x26\x87\x33\xf3\x7c\xcc\xc8\x5d\x97\x5d\xf3\x8d\x6d\x9e\x9d\x2e\x2b\x82\xd7\xaf\x7e\xf9\xf5\xa6\x71\xe8\xd1\x10\xbc\x97\x0a\xb7\xd6\xee\xe0\x83\x51\x02\xde\xd6\x35\xc4\x47\x1e\x42\xdc\x7d\xc3\x5c\xf0\xa7\x4a\x7b\xf0\xb6\x75\x0a\x41\xd9\x1c\x41\x7b\xa8\xb5\x42\xe3\x31\x87\xd6\xe4\xe8\x80\x2a\x84\xb7\x8d\x54\x15\xc2\x6b\xf1\x6a\x8a\x42\x61\x5b\x93\x73\x6d\x62\xfc\xf7\x0f\x9b\xbb\xfb\xc7\x3b\x28\x74\x8d\x30\xde\x39\x6b\x09\x72\xed\x50\x91\x75\xcf\x60\x0b\xa0\x45\x33\x72\x88\x82\x5f\x67\x7d\xcf\x79\xd7\x41\x8e\x85\x36\x08\x09\x1a\x22\xf4\x94\xc0\x78\x7f\xd5\xec\x4a\x78\x73\x0b\x5b\xe9\x11\xae\xc4\xc6\x9a\x42\x97\xe2\x0f\xa9\x76\xb2\xc4\xe9\xd1\x41\x53\x05\xf8\x9d\xd0\xe4\x70\x05\xc9\x18\x4d\x16\xd5\x6e\xfa\x9e\xb3\xae\x03\xc2\x7d\x53\x4b\x42\x48\x2a\x94\x39\xba\x04\x44\x28\xd2\x75\x10\x72\x43\x39\xbd\x6f\xac\x23\x48\x39\x4b\x8a\x3d\x25\x9c\xb3\x24\xc0\xb8\xec\x9c\x84\x82\x37\xa0\x0b\xb8\x12\x8f\x6d\x13\xb2\x3e\xea\xd2\x85\xe2\xa1\x19\x4b\x4a\x4d\x55\xbb\x15\xca\xee\xb3\x62\x34\x42\x1b\xd5\x6e\x25\x59\x97\xa1\xa1\x2c\xd7\xb2\x46\x45\x99\xff\x5a\x67\x5e\x55\xb8\x97\x63\xcd\x09\x0b\xcb\x32\x70\xf8\xb5\xd5\x0e\x73\xd8\x3e\xc3\xf0\x08\x2a\x6b\x77\x5e\x70\xf6\x05\x5e\x80\x96\xb9\xd6\x90\xde\x63\xc2\x57\x9c\xd3\x73\x83\x81\x4e\x96\xc1\x13\x7a\xd2\xa6\x7c\x0a\x26\x07\x87\xb4\x21\x74\x01\x1b\x50\x25\x29\xdc\xfa\x4a\xc6\x5e\x48\x07\x44\x13\x93\x68\x48\x12\x4f\x20\x4d\x3e\x9f\xde\xc5\x53\xeb\x07\x60\xa3\xce\x82\xb3\x63\x8b\xb9\x76\xc7\x19\x7b\x2f\x75\x7d\x6f\x0f\xe9\x8a\x33\x76\xe7\x9c\x75\xa9\x10\x62\x7e\xd2\xf5\x2b\xce\x46\xbe\x0f\x0d\x69\x6b\x40\x45\x4e\xad\x43\x0f\xaa\xd6\x61\x98\x95\x43\x19\x42\x82\xb3\xf1\x4d\xd1\x1a\x95\x5e\xdb\x78\xf0\x2b\xce\xd9\xf8\x13\x3c\xb9\x56\x51\x6c\x6c\x1b\xf2\xf0\xe9\xf3\x34\x49\x7d\x2f\x86\x64\xce\x7e\xee\x1e\xdb\x0f\xa7\x87\x21\x7f\x50\x5e\x7c\x9c\x2f\x8f\x25\x46\xb3\x58\x1f\xc4\xce\x32\xf8\x53\x53\xf5\x30\x02\x29\xac\x3b\x48\x97\x7b\x98\x90\x91\xbd\xa4\x13\x68\x2c\xb3\xd2\x88\x59\x08\x71\x01\x7a\x35\xa9\xd3\x71\xe6\x90\x5a\x37\x6a\x60\x61\x56\x61\x20\x2d\x62\x89\x5b\x90\x4d\x83\x26\x4f\x87\xf3\x3a\xa0\xf0\x42\x88\x28\x76\xdc\x9c\x17\x05\x18\x79\x9c\xf0\xfd\x31\x1d\xd9\x92\x85\x41\xac\x53\x36\xa7\xb9\x33\xa9\x1f\x29\xf9\xcf\x79\x2d\x5d\x59\xd0\x5b\x5c\x9f\xb3\x5c\xee\x53\xc4\x66\xf0\x70\x82\xe9\xd3\xe7\x09\xc4\xd4\x2c\xf4\xb2\xe1\xa3\xf3\xff\xf1\xa2\xeb\x39\x2b\xac\x83\x2f\xb1\x78\x88\x38\x69\x4a\x8c\x9d\xa6\x29\x4b\x6d\x6c\x38\xe1\xb7\x41\xe0\x38\xce\x68\x40\xc9\xba\xf6\x70\x62\x27\x9a\xb8\x40\x41\xbd\x1b\xd7\x9a\x0b\x05\xc3\x8b\x94\xe6\x8d\x5d\x43\xee\xf4\x37\x74\xf7\x72\x8f\x6b\xc8\x25\xc9\xc7\xf8\x19\x0d\xe7\x30\xee\xda\x94\x03\xf1\x20\xf1\xcc\x67\xd1\x71\x33\x4c\xdd\xc4\xec\x4c\x84\x15\x67\x6a\x0d\xe8\x5c\x88\x9d\xe1\x4c\x5f\xee\xbc\x86\x61\xb2\x06\xb5\x75\x11\x2b\xfc\xef\x16\x8c\xae\xa3\x2c\x24\x86\x5d\x47\xe7\x56\xf1\xb8\xf8\x0c\xf4\x7f\xf3\xf9\x1c\xab\xbd\xb9\x05\x25\x1e\x87\x99\xd9\x84\x95\xc1\x54\x59\x43\xf8\x9d\xc4\x3b\xa9\x76\xa5\x0b\xff\x42\xe9\x2a\x20\x59\x0c\x41\x00\xf4\xdb\x39\x9a\x73\x38\xa7\x78\x26\x40\xd3\x3a\x8f\x3e\xaa\xd1\xc7\x7b\x3c\x8c\x12\x5e\x98\x79\x0c\xfd\xd4\xd1\xf9\xd9\x89\xad\xff\xce\xb3\x33\xbb\x8e\x2d\x96\xbe\xfc\x67\x64\x3e\xfe\x0b\xff\x15\x00\x00\xff\xff\x73\x09\xc5\x5c\xd5\x08\x00\x00") + +func templateEnttestTmplBytes() ([]byte, error) { + return bindataRead( + _templateEnttestTmpl, + "template/enttest.tmpl", + ) +} + +func templateEnttestTmpl() (*asset, error) { + bytes, err := templateEnttestTmplBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "template/enttest.tmpl", size: 2261, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _templateHeaderTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x8e\xc1\x8a\xea\x30\x14\x86\xd7\xb7\x4f\xf1\x23\x5d\xc9\xbd\xa9\xd7\xdd\x0c\xb8\x90\xaa\x8c\x30\xe8\x80\xbe\x40\x4c\xfe\xb6\xc1\x92\x94\x24\xce\x20\x25\xef\x3e\xb4\x53\x41\x66\x15\xf8\xbe\x73\xf2\x9d\xbe\x2f\xe6\x59\xe9\xba\xbb\x37\x75\x13\xb1\x5c\xfc\x7f\xf9\xd7\x79\x06\xda\x88\x9d\x54\xbc\x38\x77\xc5\xde\x2a\x81\x75\xdb\x62\x1c\x0a\x18\xbc\xff\xa4\x16\xd9\xb9\x31\x01\xc1\xdd\xbc\x22\x94\xd3\x84\x09\x68\x8d\xa2\x0d\xd4\xb8\x59\x4d\x8f\xd8\x10\xeb\x4e\xaa\x86\x58\x8a\xc5\xc3\xa2\x72\x37\xab\x33\x63\x47\xff\xbe\x2f\xb7\x87\xd3\x16\x95\x69\x89\x89\x79\xe7\x22\xb4\xf1\x54\xd1\xf9\x3b\x5c\x85\xf8\x14\x8b\x9e\x14\xd9\xbc\x48\x29\xcb\xfa\x1e\x9a\x95\xb1\xc4\xac\xa1\xd4\xf4\x33\xa4\x34\xd0\x2f\x13\x1b\xe4\xe2\x6d\x84\x48\xa9\xef\x21\x7e\x1e\xb6\x81\x48\xa9\x28\x50\x0e\x57\xd7\xb4\xf4\x32\x52\xe3\x72\x07\x6d\x54\x7f\xb1\x39\xe2\x70\x3c\x63\xbb\xd9\x9f\xc5\xb0\x60\x35\xa6\x56\xde\x5d\x6b\xbc\xae\x70\x91\x81\xc8\x45\xe9\x6c\x65\x6a\xf1\x21\xd5\x55\xd6\x9c\xca\xa6\x42\x23\xc3\xce\xb0\xd5\xc8\x31\x3b\x29\xd7\x71\xbc\xea\xcf\xe3\x83\x15\x72\x31\xe2\x5f\x9b\x53\xa8\x9b\xe0\x63\xfc\x59\x7e\x07\x00\x00\xff\xff\x26\x39\x8f\x5b\xb4\x01\x00\x00") func templateHeaderTmplBytes() ([]byte, error) { @@ -1195,6 +1216,7 @@ var _bindata = map[string]func() (*asset, error){ "template/dialect/sql/tx.tmpl": templateDialectSqlTxTmpl, "template/dialect/sql/update.tmpl": templateDialectSqlUpdateTmpl, "template/ent.tmpl": templateEntTmpl, + "template/enttest.tmpl": templateEnttestTmpl, "template/header.tmpl": templateHeaderTmpl, "template/hook.tmpl": templateHookTmpl, "template/import.tmpl": templateImportTmpl, @@ -1295,11 +1317,12 @@ var _bintree = &bintree{nil, map[string]*bintree{ "update.tmpl": &bintree{templateDialectSqlUpdateTmpl, map[string]*bintree{}}, }}, }}, - "ent.tmpl": &bintree{templateEntTmpl, map[string]*bintree{}}, - "header.tmpl": &bintree{templateHeaderTmpl, map[string]*bintree{}}, - "hook.tmpl": &bintree{templateHookTmpl, map[string]*bintree{}}, - "import.tmpl": &bintree{templateImportTmpl, map[string]*bintree{}}, - "meta.tmpl": &bintree{templateMetaTmpl, map[string]*bintree{}}, + "ent.tmpl": &bintree{templateEntTmpl, map[string]*bintree{}}, + "enttest.tmpl": &bintree{templateEnttestTmpl, map[string]*bintree{}}, + "header.tmpl": &bintree{templateHeaderTmpl, map[string]*bintree{}}, + "hook.tmpl": &bintree{templateHookTmpl, map[string]*bintree{}}, + "import.tmpl": &bintree{templateImportTmpl, map[string]*bintree{}}, + "meta.tmpl": &bintree{templateMetaTmpl, map[string]*bintree{}}, "migrate": &bintree{nil, map[string]*bintree{ "migrate.tmpl": &bintree{templateMigrateMigrateTmpl, map[string]*bintree{}}, "schema.tmpl": &bintree{templateMigrateSchemaTmpl, map[string]*bintree{}}, diff --git a/entc/gen/template.go b/entc/gen/template.go index 8a924276b..983668828 100644 --- a/entc/gen/template.go +++ b/entc/gen/template.go @@ -120,6 +120,10 @@ var ( Name: "runtime/ent", Format: "runtime.go", }, + { + Name: "enttest", + Format: "enttest/enttest.go", + }, { Name: "runtime/pkg", Format: "runtime/runtime.go", diff --git a/entc/gen/template/enttest.tmpl b/entc/gen/template/enttest.tmpl new file mode 100644 index 000000000..55813cbab --- /dev/null +++ b/entc/gen/template/enttest.tmpl @@ -0,0 +1,100 @@ +{{/* +Copyright 2019-present Facebook Inc. All rights reserved. +This source code is licensed under the Apache 2.0 license found +in the LICENSE file in the root directory of this source tree. +*/}} + +{{ define "enttest" }} + +{{ $pkg := base $.Config.Package }} + +{{ with extend $ "Package" "enttest" -}} + {{ template "header" . }} +{{ end }} + +import ( + "fmt" + + "{{ $.Config.Package }}" + {{- if $.SupportMigrate }} + "github.com/facebookincubator/ent/dialect/sql/schema" + {{- end }} + + // required by schema hooks. + _ "{{ $.Config.Package }}/runtime" +) + +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 []{{ $pkg }}.Option + {{- if $.SupportMigrate }} + migrateOpts []schema.MigrateOption + {{- end }} + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...{{ $pkg }}.Option) Option { + return func(o *options) { + o.opts = append(o.opts, opts...) + } +} + +{{- if $.SupportMigrate }} +// WithMigrateOptions forwards options to auto migration. +func WithMigrateOptions(opts ...schema.MigrateOption) Option { + return func(o *options) { + o.migrateOpts = append(o.migrateOpts, opts...) + } +} +{{- end }} + +func newOptions(opts []Option) *options { + o := &options{} + for _, opt := range opts { + opt(o) + } + return o +} + +// Open calls {{ $pkg }}.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *{{ $pkg }}.Client { + o := newOptions(opts) + c, err := {{ $pkg }}.Open(driverName, dataSourceName, o.opts...) + if err != nil { + t.Error(err) + t.FailNow() + } + {{- if $.SupportMigrate }} + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + {{- end }} + return c +} + +// NewClient calls {{ $pkg }}.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *{{ $pkg }}.Client { + o := newOptions(opts) + c := {{ $pkg }}.NewClient(o.opts...) + {{- if $.SupportMigrate }} + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + {{- end }} + return c +} + +{{ end }} diff --git a/entc/integration/config/ent/enttest/enttest.go b/entc/integration/config/ent/enttest/enttest.go new file mode 100644 index 000000000..4537c0b72 --- /dev/null +++ b/entc/integration/config/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/config/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/config/ent/runtime" +) + +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 +} diff --git a/entc/integration/customid/ent/enttest/enttest.go b/entc/integration/customid/ent/enttest/enttest.go new file mode 100644 index 000000000..4375b4a6a --- /dev/null +++ b/entc/integration/customid/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/customid/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/customid/ent/runtime" +) + +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 +} diff --git a/entc/integration/ent/enttest/enttest.go b/entc/integration/ent/enttest/enttest.go new file mode 100644 index 000000000..e2044a942 --- /dev/null +++ b/entc/integration/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/ent/runtime" +) + +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 +} diff --git a/entc/integration/gremlin/ent/enttest/enttest.go b/entc/integration/gremlin/ent/enttest/enttest.go new file mode 100644 index 000000000..d56366d2d --- /dev/null +++ b/entc/integration/gremlin/ent/enttest/enttest.go @@ -0,0 +1,63 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "github.com/facebookincubator/ent/entc/integration/gremlin/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/gremlin/ent/runtime" +) + +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 + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...ent.Option) Option { + return func(o *options) { + o.opts = append(o.opts, 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() + } + 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...) + return c +} diff --git a/entc/integration/hooks/ent/enttest/enttest.go b/entc/integration/hooks/ent/enttest/enttest.go new file mode 100644 index 000000000..6c7ce6ab9 --- /dev/null +++ b/entc/integration/hooks/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/hooks/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/hooks/ent/runtime" +) + +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 +} diff --git a/entc/integration/idtype/ent/enttest/enttest.go b/entc/integration/idtype/ent/enttest/enttest.go new file mode 100644 index 000000000..b56cfcbce --- /dev/null +++ b/entc/integration/idtype/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/idtype/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/idtype/ent/runtime" +) + +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 +} diff --git a/entc/integration/json/ent/enttest/enttest.go b/entc/integration/json/ent/enttest/enttest.go new file mode 100644 index 000000000..68dffd82e --- /dev/null +++ b/entc/integration/json/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/json/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/json/ent/runtime" +) + +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 +} diff --git a/entc/integration/migrate/entv1/enttest/enttest.go b/entc/integration/migrate/entv1/enttest/enttest.go new file mode 100644 index 000000000..51ca760b7 --- /dev/null +++ b/entc/integration/migrate/entv1/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/migrate/entv1" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/migrate/entv1/runtime" +) + +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 []entv1.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...entv1.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 entv1.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *entv1.Client { + o := newOptions(opts) + c, err := entv1.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 entv1.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *entv1.Client { + o := newOptions(opts) + c := entv1.NewClient(o.opts...) + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + return c +} diff --git a/entc/integration/migrate/entv2/enttest/enttest.go b/entc/integration/migrate/entv2/enttest/enttest.go new file mode 100644 index 000000000..6be77886a --- /dev/null +++ b/entc/integration/migrate/entv2/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/migrate/entv2" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/migrate/entv2/runtime" +) + +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 []entv2.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...entv2.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 entv2.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *entv2.Client { + o := newOptions(opts) + c, err := entv2.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 entv2.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *entv2.Client { + o := newOptions(opts) + c := entv2.NewClient(o.opts...) + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + return c +} diff --git a/entc/integration/privacy/ent/enttest/enttest.go b/entc/integration/privacy/ent/enttest/enttest.go new file mode 100644 index 000000000..f073b9c1e --- /dev/null +++ b/entc/integration/privacy/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/privacy/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/privacy/ent/runtime" +) + +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 +} diff --git a/entc/integration/template/ent/enttest/enttest.go b/entc/integration/template/ent/enttest/enttest.go new file mode 100644 index 000000000..50a098049 --- /dev/null +++ b/entc/integration/template/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/entc/integration/template/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/entc/integration/template/ent/runtime" +) + +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 +} diff --git a/examples/edgeindex/ent/enttest/enttest.go b/examples/edgeindex/ent/enttest/enttest.go new file mode 100644 index 000000000..820655040 --- /dev/null +++ b/examples/edgeindex/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/edgeindex/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/edgeindex/ent/runtime" +) + +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 +} diff --git a/examples/entcpkg/ent/enttest/enttest.go b/examples/entcpkg/ent/enttest/enttest.go new file mode 100644 index 000000000..62bd26ff2 --- /dev/null +++ b/examples/entcpkg/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/entcpkg/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/entcpkg/ent/runtime" +) + +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 +} diff --git a/examples/m2m2types/ent/enttest/enttest.go b/examples/m2m2types/ent/enttest/enttest.go new file mode 100644 index 000000000..eb34afab2 --- /dev/null +++ b/examples/m2m2types/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/m2m2types/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/m2m2types/ent/runtime" +) + +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 +} diff --git a/examples/m2mbidi/ent/enttest/enttest.go b/examples/m2mbidi/ent/enttest/enttest.go new file mode 100644 index 000000000..070a8f7d8 --- /dev/null +++ b/examples/m2mbidi/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/m2mbidi/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/m2mbidi/ent/runtime" +) + +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 +} diff --git a/examples/m2mrecur/ent/enttest/enttest.go b/examples/m2mrecur/ent/enttest/enttest.go new file mode 100644 index 000000000..cc02fd7ab --- /dev/null +++ b/examples/m2mrecur/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/m2mrecur/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/m2mrecur/ent/runtime" +) + +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 +} diff --git a/examples/o2m2types/ent/enttest/enttest.go b/examples/o2m2types/ent/enttest/enttest.go new file mode 100644 index 000000000..c53e7f81a --- /dev/null +++ b/examples/o2m2types/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/o2m2types/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/o2m2types/ent/runtime" +) + +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 +} diff --git a/examples/o2mrecur/ent/enttest/enttest.go b/examples/o2mrecur/ent/enttest/enttest.go new file mode 100644 index 000000000..0d6ec5738 --- /dev/null +++ b/examples/o2mrecur/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/o2mrecur/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/o2mrecur/ent/runtime" +) + +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 +} diff --git a/examples/o2o2types/ent/enttest/enttest.go b/examples/o2o2types/ent/enttest/enttest.go new file mode 100644 index 000000000..a03462d41 --- /dev/null +++ b/examples/o2o2types/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/o2o2types/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/o2o2types/ent/runtime" +) + +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 +} diff --git a/examples/o2obidi/ent/enttest/enttest.go b/examples/o2obidi/ent/enttest/enttest.go new file mode 100644 index 000000000..aa7e096fb --- /dev/null +++ b/examples/o2obidi/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/o2obidi/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/o2obidi/ent/runtime" +) + +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 +} diff --git a/examples/o2orecur/ent/enttest/enttest.go b/examples/o2orecur/ent/enttest/enttest.go new file mode 100644 index 000000000..36794baf7 --- /dev/null +++ b/examples/o2orecur/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/o2orecur/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/o2orecur/ent/runtime" +) + +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 +} diff --git a/examples/start/ent/enttest/enttest.go b/examples/start/ent/enttest/enttest.go new file mode 100644 index 000000000..8aaa0822d --- /dev/null +++ b/examples/start/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/start/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/start/ent/runtime" +) + +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 +} diff --git a/examples/traversal/ent/enttest/enttest.go b/examples/traversal/ent/enttest/enttest.go new file mode 100644 index 000000000..59c085f99 --- /dev/null +++ b/examples/traversal/ent/enttest/enttest.go @@ -0,0 +1,82 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/examples/traversal/ent" + + // required by schema hooks. + _ "github.com/facebookincubator/ent/examples/traversal/ent/runtime" +) + +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 +}