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

685 lines
17 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 testAliases(t *testing.T) {
t.Parallel()
query := Aliases()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testAliasesDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAliasesQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().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 := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAliasesSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := AliasSlice{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 := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testAliasesExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := AliasExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if Alias exists: %s", err)
}
if !e {
t.Errorf("Expected AliasExists to return true, but got false.")
}
}
func testAliasesFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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)
}
aliasFound, err := FindAlias(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if aliasFound == nil {
t.Error("want a record, got nil")
}
}
func testAliasesBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 = Aliases().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testAliasesOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testAliasesAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
aliasOne := &Alias{}
aliasTwo := &Alias{}
if err = randomize.Struct(seed, aliasOne, aliasDBTypes, false, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
if err = randomize.Struct(seed, aliasTwo, aliasDBTypes, false, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = aliasOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = aliasTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Aliases().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testAliasesCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
aliasOne := &Alias{}
aliasTwo := &Alias{}
if err = randomize.Struct(seed, aliasOne, aliasDBTypes, false, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
if err = randomize.Struct(seed, aliasTwo, aliasDBTypes, false, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = aliasOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = aliasTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func aliasBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func aliasAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Alias) error {
*o = Alias{}
return nil
}
func testAliasesHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &Alias{}
o := &Alias{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, aliasDBTypes, false); err != nil {
t.Errorf("Unable to randomize Alias object: %s", err)
}
AddAliasHook(boil.BeforeInsertHook, aliasBeforeInsertHook)
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)
}
aliasBeforeInsertHooks = []AliasHook{}
AddAliasHook(boil.AfterInsertHook, aliasAfterInsertHook)
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)
}
aliasAfterInsertHooks = []AliasHook{}
AddAliasHook(boil.AfterSelectHook, aliasAfterSelectHook)
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)
}
aliasAfterSelectHooks = []AliasHook{}
AddAliasHook(boil.BeforeUpdateHook, aliasBeforeUpdateHook)
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)
}
aliasBeforeUpdateHooks = []AliasHook{}
AddAliasHook(boil.AfterUpdateHook, aliasAfterUpdateHook)
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)
}
aliasAfterUpdateHooks = []AliasHook{}
AddAliasHook(boil.BeforeDeleteHook, aliasBeforeDeleteHook)
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)
}
aliasBeforeDeleteHooks = []AliasHook{}
AddAliasHook(boil.AfterDeleteHook, aliasAfterDeleteHook)
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)
}
aliasAfterDeleteHooks = []AliasHook{}
AddAliasHook(boil.BeforeUpsertHook, aliasBeforeUpsertHook)
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)
}
aliasBeforeUpsertHooks = []AliasHook{}
AddAliasHook(boil.AfterUpsertHook, aliasAfterUpsertHook)
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)
}
aliasAfterUpsertHooks = []AliasHook{}
}
func testAliasesInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testAliasesInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(aliasColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := Aliases().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testAliasesReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 testAliasesReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := AliasSlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testAliasesSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
aliasDBTypes = map[string]string{`ID`: `INT`, `Name`: `TEXT`, `PubKey`: `TEXT`}
_ = bytes.MinRead
)
func testAliasesUpdate(t *testing.T) {
t.Parallel()
if 0 == len(aliasPrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(aliasAllColumns) == len(aliasPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().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, aliasDBTypes, true, aliasPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Alias 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 testAliasesSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(aliasAllColumns) == len(aliasPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Alias{}
if err = randomize.Struct(seed, o, aliasDBTypes, true, aliasColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Alias 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 := Aliases().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, aliasDBTypes, true, aliasPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Alias struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(aliasAllColumns, aliasPrimaryKeyColumns) {
fields = aliasAllColumns
} else {
fields = strmangle.SetComplement(
aliasAllColumns,
aliasPrimaryKeyColumns,
)
}
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 := AliasSlice{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)
}
}