Don't generate model tests

They don't work cleanly from the repo root and they need sqlite to be
installed.

On a higher level, I expect the tests for generated code to pass if the
generation worked. Also we (will) have tests that drive the generated
code, too.
This commit is contained in:
Henry 2021-02-09 17:47:46 +01:00
parent a9865f1cb8
commit 8029909ecf
6 changed files with 2 additions and 1071 deletions

View File

@ -3,5 +3,5 @@
set -e
go test
sqlboiler sqlite3 --wipe
echo "all done!"
sqlboiler sqlite3 --wipe --no-tests
echo "all done!"

View File

@ -1,684 +0,0 @@
// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"bytes"
"context"
"reflect"
"testing"
"github.com/volatiletech/randomize"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries"
"github.com/volatiletech/strmangle"
)
var (
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
// so force a package dependency in case they don't.
_ = queries.Equal
)
func testAuthFallbacks(t *testing.T) {
t.Parallel()
query := AuthFallbacks()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testAuthFallbacksDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := o.Delete(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAuthFallbacksQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := AuthFallbacks().DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAuthFallbacksSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := AuthFallbackSlice{o}
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAuthFallbacksExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
e, err := AuthFallbackExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if AuthFallback exists: %s", err)
}
if !e {
t.Errorf("Expected AuthFallbackExists to return true, but got false.")
}
}
func testAuthFallbacksFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
authFallbackFound, err := FindAuthFallback(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if authFallbackFound == nil {
t.Error("want a record, got nil")
}
}
func testAuthFallbacksBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = AuthFallbacks().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testAuthFallbacksOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if x, err := AuthFallbacks().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testAuthFallbacksAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
authFallbackOne := &AuthFallback{}
authFallbackTwo := &AuthFallback{}
if err = randomize.Struct(seed, authFallbackOne, authFallbackDBTypes, false, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
if err = randomize.Struct(seed, authFallbackTwo, authFallbackDBTypes, false, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = authFallbackOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = authFallbackTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := AuthFallbacks().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testAuthFallbacksCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
authFallbackOne := &AuthFallback{}
authFallbackTwo := &AuthFallback{}
if err = randomize.Struct(seed, authFallbackOne, authFallbackDBTypes, false, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
if err = randomize.Struct(seed, authFallbackTwo, authFallbackDBTypes, false, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = authFallbackOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = authFallbackTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func authFallbackBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func authFallbackAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *AuthFallback) error {
*o = AuthFallback{}
return nil
}
func testAuthFallbacksHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &AuthFallback{}
o := &AuthFallback{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, authFallbackDBTypes, false); err != nil {
t.Errorf("Unable to randomize AuthFallback object: %s", err)
}
AddAuthFallbackHook(boil.BeforeInsertHook, authFallbackBeforeInsertHook)
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
}
authFallbackBeforeInsertHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.AfterInsertHook, authFallbackAfterInsertHook)
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
}
authFallbackAfterInsertHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.AfterSelectHook, authFallbackAfterSelectHook)
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
}
authFallbackAfterSelectHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.BeforeUpdateHook, authFallbackBeforeUpdateHook)
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
}
authFallbackBeforeUpdateHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.AfterUpdateHook, authFallbackAfterUpdateHook)
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
}
authFallbackAfterUpdateHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.BeforeDeleteHook, authFallbackBeforeDeleteHook)
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
}
authFallbackBeforeDeleteHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.AfterDeleteHook, authFallbackAfterDeleteHook)
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
}
authFallbackAfterDeleteHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.BeforeUpsertHook, authFallbackBeforeUpsertHook)
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
}
authFallbackBeforeUpsertHooks = []AuthFallbackHook{}
AddAuthFallbackHook(boil.AfterUpsertHook, authFallbackAfterUpsertHook)
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
}
authFallbackAfterUpsertHooks = []AuthFallbackHook{}
}
func testAuthFallbacksInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testAuthFallbacksInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(authFallbackColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testAuthFallbacksReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = o.Reload(ctx, tx); err != nil {
t.Error(err)
}
}
func testAuthFallbacksReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := AuthFallbackSlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testAuthFallbacksSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := AuthFallbacks().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
authFallbackDBTypes = map[string]string{`ID`: `INT`, `Name`: `TEXT`, `PasswordHash`: `BLOB`}
_ = bytes.MinRead
)
func testAuthFallbacksUpdate(t *testing.T) {
t.Parallel()
if 0 == len(authFallbackPrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(authFallbackAllColumns) == len(authFallbackPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only affect one row but affected", rowsAff)
}
}
func testAuthFallbacksSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(authFallbackAllColumns) == len(authFallbackPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &AuthFallback{}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := AuthFallbacks().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, authFallbackDBTypes, true, authFallbackPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize AuthFallback struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(authFallbackAllColumns, authFallbackPrimaryKeyColumns) {
fields = authFallbackAllColumns
} else {
fields = strmangle.SetComplement(
authFallbackAllColumns,
authFallbackPrimaryKeyColumns,
)
}
value := reflect.Indirect(reflect.ValueOf(o))
typ := reflect.TypeOf(o).Elem()
n := typ.NumField()
updateMap := M{}
for _, col := range fields {
for i := 0; i < n; i++ {
f := typ.Field(i)
if f.Tag.Get("boil") == col {
updateMap[col] = value.Field(i).Interface()
}
}
}
slice := AuthFallbackSlice{o}
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("wanted one record updated but got", rowsAff)
}
}

View File

@ -1,119 +0,0 @@
// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"database/sql"
"flag"
"fmt"
"math/rand"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/spf13/viper"
"github.com/volatiletech/sqlboiler/v4/boil"
)
var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements")
var flagConfigFile = flag.String("test.config", "", "Overrides the default config")
const outputDirDepth = 1
var (
dbMain tester
)
type tester interface {
setup() error
conn() (*sql.DB, error)
teardown() error
}
func TestMain(m *testing.M) {
if dbMain == nil {
fmt.Println("no dbMain tester interface was ready")
os.Exit(-1)
}
rand.Seed(time.Now().UnixNano())
flag.Parse()
var err error
// Load configuration
err = initViper()
if err != nil {
fmt.Println("unable to load config file")
os.Exit(-2)
}
// Set DebugMode so we can see generated sql statements
boil.DebugMode = *flagDebugMode
if err = dbMain.setup(); err != nil {
fmt.Println("Unable to execute setup:", err)
os.Exit(-4)
}
conn, err := dbMain.conn()
if err != nil {
fmt.Println("failed to get connection:", err)
}
var code int
boil.SetDB(conn)
code = m.Run()
if err = dbMain.teardown(); err != nil {
fmt.Println("Unable to execute teardown:", err)
os.Exit(-5)
}
os.Exit(code)
}
func initViper() error {
if flagConfigFile != nil && *flagConfigFile != "" {
viper.SetConfigFile(*flagConfigFile)
if err := viper.ReadInConfig(); err != nil {
return err
}
return nil
}
var err error
viper.SetConfigName("sqlboiler")
configHome := os.Getenv("XDG_CONFIG_HOME")
homePath := os.Getenv("HOME")
wd, err := os.Getwd()
if err != nil {
wd = strings.Repeat("../", outputDirDepth)
} else {
wd = wd + strings.Repeat("/..", outputDirDepth)
}
configPaths := []string{wd}
if len(configHome) > 0 {
configPaths = append(configPaths, filepath.Join(configHome, "sqlboiler"))
} else {
configPaths = append(configPaths, filepath.Join(homePath, ".config/sqlboiler"))
}
for _, p := range configPaths {
viper.AddConfigPath(p)
}
// Ignore errors here, fall back to defaults and validation to provide errs
_ = viper.ReadInConfig()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
return nil
}

View File

@ -1,52 +0,0 @@
// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"regexp"
"github.com/volatiletech/sqlboiler/v4/boil"
)
var dbNameRand *rand.Rand
func MustTx(transactor boil.ContextTransactor, err error) boil.ContextTransactor {
if err != nil {
panic(fmt.Sprintf("Cannot create a transactor: %s", err))
}
return transactor
}
func newFKeyDestroyer(regex *regexp.Regexp, reader io.Reader) io.Reader {
return &fKeyDestroyer{
reader: reader,
rgx: regex,
}
}
type fKeyDestroyer struct {
reader io.Reader
buf *bytes.Buffer
rgx *regexp.Regexp
}
func (f *fKeyDestroyer) Read(b []byte) (int, error) {
if f.buf == nil {
all, err := ioutil.ReadAll(f.reader)
if err != nil {
return 0, err
}
all = bytes.Replace(all, []byte{'\r', '\n'}, []byte{'\n'}, -1)
all = f.rgx.ReplaceAll(all, []byte{})
f.buf = bytes.NewBuffer(all)
}
return f.buf.Read(b)
}

View File

@ -1,121 +0,0 @@
// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import "testing"
// This test suite runs each operation test in parallel.
// Example, if your database has 3 tables, the suite will run:
// table1, table2 and table3 Delete in parallel
// table1, table2 and table3 Insert in parallel, and so forth.
// It does NOT run each operation group in parallel.
// Separating the tests thusly grants avoidance of Postgres deadlocks.
func TestParent(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacks)
}
func TestDelete(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksDelete)
}
func TestQueryDeleteAll(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksQueryDeleteAll)
}
func TestSliceDeleteAll(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksSliceDeleteAll)
}
func TestExists(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksExists)
}
func TestFind(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksFind)
}
func TestBind(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksBind)
}
func TestOne(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksOne)
}
func TestAll(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksAll)
}
func TestCount(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksCount)
}
func TestHooks(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksHooks)
}
func TestInsert(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksInsert)
t.Run("AuthFallbacks", testAuthFallbacksInsertWhitelist)
}
// TestToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestToOne(t *testing.T) {}
// TestOneToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOne(t *testing.T) {}
// TestToMany tests cannot be run in parallel
// or deadlocks can occur.
func TestToMany(t *testing.T) {}
// TestToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestToOneSet(t *testing.T) {}
// TestToOneRemove tests cannot be run in parallel
// or deadlocks can occur.
func TestToOneRemove(t *testing.T) {}
// TestOneToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOneSet(t *testing.T) {}
// TestOneToOneRemove tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOneRemove(t *testing.T) {}
// TestToManyAdd tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyAdd(t *testing.T) {}
// TestToManySet tests cannot be run in parallel
// or deadlocks can occur.
func TestToManySet(t *testing.T) {}
// TestToManyRemove tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyRemove(t *testing.T) {}
func TestReload(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksReload)
}
func TestReloadAll(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksReloadAll)
}
func TestSelect(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksSelect)
}
func TestUpdate(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksUpdate)
}
func TestSliceUpdateAll(t *testing.T) {
t.Run("AuthFallbacks", testAuthFallbacksSliceUpdateAll)
}

View File

@ -1,93 +0,0 @@
// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"database/sql"
"fmt"
"io"
"math/rand"
"os"
"os/exec"
"path/filepath"
"regexp"
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
"github.com/spf13/viper"
)
var rgxSQLitekey = regexp.MustCompile(`(?mi)((,\n)?\s+foreign key.*?\n)+`)
type sqliteTester struct {
dbConn *sql.DB
dbName string
testDBName string
}
func init() {
dbMain = &sqliteTester{}
}
func (s *sqliteTester) setup() error {
var err error
s.dbName = viper.GetString("sqlite3.dbname")
if len(s.dbName) == 0 {
return errors.New("no dbname specified")
}
s.testDBName = filepath.Join(os.TempDir(), fmt.Sprintf("boil-sqlite3-%d.sql", rand.Int()))
dumpCmd := exec.Command("sqlite3", "-cmd", ".dump", s.dbName)
createCmd := exec.Command("sqlite3", s.testDBName)
r, w := io.Pipe()
dumpCmd.Stdout = w
createCmd.Stdin = newFKeyDestroyer(rgxSQLitekey, r)
if err = dumpCmd.Start(); err != nil {
return errors.Wrap(err, "failed to start sqlite3 dump command")
}
if err = createCmd.Start(); err != nil {
return errors.Wrap(err, "failed to start sqlite3 create command")
}
if err = dumpCmd.Wait(); err != nil {
fmt.Println(err)
return errors.Wrap(err, "failed to wait for sqlite3 dump command")
}
w.Close() // After dumpCmd is done, close the write end of the pipe
if err = createCmd.Wait(); err != nil {
fmt.Println(err)
return errors.Wrap(err, "failed to wait for sqlite3 create command")
}
return nil
}
func (s *sqliteTester) teardown() error {
if s.dbConn != nil {
s.dbConn.Close()
}
return os.Remove(s.testDBName)
}
func (s *sqliteTester) conn() (*sql.DB, error) {
if s.dbConn != nil {
return s.dbConn, nil
}
var err error
s.dbConn, err = sql.Open("sqlite3", fmt.Sprintf("file:%s?_loc=UTC", s.testDBName))
if err != nil {
return nil, err
}
return s.dbConn, nil
}