Files
gocryptotrader/database/models/sqlite3/withdrawal_history_test.go
Andrew b26ec86d43 Withdraw additional functionality (validation/submission/tracking) (#409)
* reworked request struct and exchange response started work on validation system

* removed import cycle until work around

* Added intial withdraw support via CLI added

* Added Crypto command to gctcli

* moved var declartion to single line

* Test updates for binance and anx

* All exchange tests have been updated test coverage added to validate

* First pass at adding withdrawl select from database

* started adding basic lru cache system

* Added basic LRU cache including Add Get Remove Contains ContainsOrAdd Clear

* wording changes on comments

* removed exported var's in strut as they are not required

* Added README

* README updates

* corrected ID on commands

* rm line :D

* merged in origin/cache

* linter fixes (gofmt)

* Added basic cache lookup to events

* swapped to mutex over rwmutex updated comments

* unexported getNewest & getOldest

* unexported getNewest & getOldest

* Updated comments and cited references in source

* updated comments

* WIP

* Migrated exchange WithdrawFiat wrapper to new struct response

* Migrated exchange WithdrawFiat wrapper to new struct response

* started work on bank management

* Added exchange level banking details back with migration to banking package

* Removed broken tests for now

* Added validation to bank accounts

* removed duplicate bank details from withdraw struct

* Test coverage increased

* gofmt

* merged upstream/master with clean up

* First pass at adding command line linking to gctcli

* added validation for crypto address, added gctcli support to retreive previous withdrawal requests

* general cleanup

* general cleanup

* reordered imports

* Increased test coverage moved to database sublogger

* Pass incorrect currency no longer return error from c.CheckBankAccountConfig

* remove TestMain() for now as other tests in this package will need to be reworked

* Happy little race car

* Reverted to upstream tests

* Added test covarege for validation method, corrected response on cli protobuf

* query clean up and removal of duplicated code

* cleaned up queries into singlem ethod increased test coverage

* Migrated international fund withdraw to new exchange response and added cache size override

* Migrated international fund withdraw to new exchange response and added cache size override

* Extended gctcli commands

* lowered default cache to 25

* small code clean up

* added get by date method

* add returned error

* cli commands cleaing return error on nil results to fix out of bounds

* merged write & read helpers into one for test coverage and increased engine/withdraw test coverage

* gofmt

* Added test coverage for valid ID

* removed unused param

* converted to use timestamp package from protobuf

* gofmt

* use built in RFC3339 timestamp

* remove setting of CreatedAt & UpdatedAt and allow ORm to take care of it

* also use ptype on byid

* code flow improvements

* remove inverse conditional check and linters run

* removed test data

* removed comment

* removed comment

* also write failures to database for auditing

* converted to use default time for start & end

* Default to time.Now() minus 30 days

* Default to time.Now() minus 30 days

* small code clean up

* fixed missing semicolon on migrations, code clean up

* updated sqlite migrations

* Added additonal check for exchange level bank account if global is not found

* case sensativity fix for currency names

* use correct compare

* test coverage fixed

* removed space

* return pointer to banking.Account

* return pointer to banking.Account

* added else check back to validate()

* Added empty string as default to migration over NULL due to retrivial of data
2020-02-26 15:45:13 +11:00

992 lines
28 KiB
Go

// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sqlite3
import (
"bytes"
"context"
"reflect"
"testing"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries"
"github.com/thrasher-corp/sqlboiler/randomize"
"github.com/thrasher-corp/sqlboiler/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 testWithdrawalHistories(t *testing.T) {
t.Parallel()
query := WithdrawalHistories()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testWithdrawalHistoriesDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testWithdrawalHistoriesQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().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 := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testWithdrawalHistoriesSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistorySlice{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 := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testWithdrawalHistoriesExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistoryExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if WithdrawalHistory exists: %s", err)
}
if !e {
t.Errorf("Expected WithdrawalHistoryExists to return true, but got false.")
}
}
func testWithdrawalHistoriesFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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)
}
withdrawalHistoryFound, err := FindWithdrawalHistory(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if withdrawalHistoryFound == nil {
t.Error("want a record, got nil")
}
}
func testWithdrawalHistoriesBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 = WithdrawalHistories().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testWithdrawalHistoriesOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testWithdrawalHistoriesAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
withdrawalHistoryOne := &WithdrawalHistory{}
withdrawalHistoryTwo := &WithdrawalHistory{}
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := WithdrawalHistories().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testWithdrawalHistoriesCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
withdrawalHistoryOne := &WithdrawalHistory{}
withdrawalHistoryTwo := &WithdrawalHistory{}
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func withdrawalHistoryBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func withdrawalHistoryAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
*o = WithdrawalHistory{}
return nil
}
func testWithdrawalHistoriesHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &WithdrawalHistory{}
o := &WithdrawalHistory{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, false); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory object: %s", err)
}
AddWithdrawalHistoryHook(boil.BeforeInsertHook, withdrawalHistoryBeforeInsertHook)
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)
}
withdrawalHistoryBeforeInsertHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.AfterInsertHook, withdrawalHistoryAfterInsertHook)
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)
}
withdrawalHistoryAfterInsertHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.AfterSelectHook, withdrawalHistoryAfterSelectHook)
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)
}
withdrawalHistoryAfterSelectHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.BeforeUpdateHook, withdrawalHistoryBeforeUpdateHook)
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)
}
withdrawalHistoryBeforeUpdateHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.AfterUpdateHook, withdrawalHistoryAfterUpdateHook)
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)
}
withdrawalHistoryAfterUpdateHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.BeforeDeleteHook, withdrawalHistoryBeforeDeleteHook)
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)
}
withdrawalHistoryBeforeDeleteHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.AfterDeleteHook, withdrawalHistoryAfterDeleteHook)
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)
}
withdrawalHistoryAfterDeleteHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.BeforeUpsertHook, withdrawalHistoryBeforeUpsertHook)
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)
}
withdrawalHistoryBeforeUpsertHooks = []WithdrawalHistoryHook{}
AddWithdrawalHistoryHook(boil.AfterUpsertHook, withdrawalHistoryAfterUpsertHook)
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)
}
withdrawalHistoryAfterUpsertHooks = []WithdrawalHistoryHook{}
}
func testWithdrawalHistoriesInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testWithdrawalHistoriesInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalHistoryColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := WithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testWithdrawalHistoryToManyWithdrawalCryptos(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c WithdrawalCrypto
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
t.Fatal(err)
}
b.WithdrawalHistoryID = a.ID
c.WithdrawalHistoryID = a.ID
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := a.WithdrawalCryptos().All(ctx, tx)
if err != nil {
t.Fatal(err)
}
bFound, cFound := false, false
for _, v := range check {
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
bFound = true
}
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
cFound = true
}
}
if !bFound {
t.Error("expected to find b")
}
if !cFound {
t.Error("expected to find c")
}
slice := WithdrawalHistorySlice{&a}
if err = a.L.LoadWithdrawalCryptos(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.WithdrawalCryptos); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
a.R.WithdrawalCryptos = nil
if err = a.L.LoadWithdrawalCryptos(ctx, tx, true, &a, nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.WithdrawalCryptos); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
if t.Failed() {
t.Logf("%#v", check)
}
}
func testWithdrawalHistoryToManyWithdrawalFiats(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c WithdrawalFiat
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
t.Fatal(err)
}
b.WithdrawalHistoryID = a.ID
c.WithdrawalHistoryID = a.ID
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := a.WithdrawalFiats().All(ctx, tx)
if err != nil {
t.Fatal(err)
}
bFound, cFound := false, false
for _, v := range check {
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
bFound = true
}
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
cFound = true
}
}
if !bFound {
t.Error("expected to find b")
}
if !cFound {
t.Error("expected to find c")
}
slice := WithdrawalHistorySlice{&a}
if err = a.L.LoadWithdrawalFiats(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.WithdrawalFiats); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
a.R.WithdrawalFiats = nil
if err = a.L.LoadWithdrawalFiats(ctx, tx, true, &a, nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.WithdrawalFiats); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
if t.Failed() {
t.Logf("%#v", check)
}
}
func testWithdrawalHistoryToManyAddOpWithdrawalCryptos(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c, d, e WithdrawalCrypto
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*WithdrawalCrypto{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
foreignersSplitByInsertion := [][]*WithdrawalCrypto{
{&b, &c},
{&d, &e},
}
for i, x := range foreignersSplitByInsertion {
err = a.AddWithdrawalCryptos(ctx, tx, i != 0, x...)
if err != nil {
t.Fatal(err)
}
first := x[0]
second := x[1]
if a.ID != first.WithdrawalHistoryID {
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
}
if a.ID != second.WithdrawalHistoryID {
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
}
if first.R.WithdrawalHistory != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if second.R.WithdrawalHistory != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if a.R.WithdrawalCryptos[i*2] != first {
t.Error("relationship struct slice not set to correct value")
}
if a.R.WithdrawalCryptos[i*2+1] != second {
t.Error("relationship struct slice not set to correct value")
}
count, err := a.WithdrawalCryptos().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if want := int64((i + 1) * 2); count != want {
t.Error("want", want, "got", count)
}
}
}
func testWithdrawalHistoryToManyAddOpWithdrawalFiats(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c, d, e WithdrawalFiat
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*WithdrawalFiat{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
foreignersSplitByInsertion := [][]*WithdrawalFiat{
{&b, &c},
{&d, &e},
}
for i, x := range foreignersSplitByInsertion {
err = a.AddWithdrawalFiats(ctx, tx, i != 0, x...)
if err != nil {
t.Fatal(err)
}
first := x[0]
second := x[1]
if a.ID != first.WithdrawalHistoryID {
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
}
if a.ID != second.WithdrawalHistoryID {
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
}
if first.R.WithdrawalHistory != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if second.R.WithdrawalHistory != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if a.R.WithdrawalFiats[i*2] != first {
t.Error("relationship struct slice not set to correct value")
}
if a.R.WithdrawalFiats[i*2+1] != second {
t.Error("relationship struct slice not set to correct value")
}
count, err := a.WithdrawalFiats().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if want := int64((i + 1) * 2); count != want {
t.Error("want", want, "got", count)
}
}
}
func testWithdrawalHistoriesReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 testWithdrawalHistoriesReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistorySlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testWithdrawalHistoriesSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `Exchange`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
_ = bytes.MinRead
)
func testWithdrawalHistoriesUpdate(t *testing.T) {
t.Parallel()
if 0 == len(withdrawalHistoryPrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().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, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 testWithdrawalHistoriesSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &WithdrawalHistory{}
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory 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 := WithdrawalHistories().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, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(withdrawalHistoryAllColumns, withdrawalHistoryPrimaryKeyColumns) {
fields = withdrawalHistoryAllColumns
} else {
fields = strmangle.SetComplement(
withdrawalHistoryAllColumns,
withdrawalHistoryPrimaryKeyColumns,
)
}
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 := WithdrawalHistorySlice{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)
}
}