go-ssb-room/admindb/sqlite/models/auth_fallback_test.go

685 lines
18 KiB
Go

// 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)
}
}