mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 07:26:48 +00:00
* 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
1389 lines
40 KiB
Go
1389 lines
40 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 postgres
|
|
|
|
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 testWithdrawalHistoryToManyWithdrawalCryptoWithdrawalCryptos(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)
|
|
}
|
|
|
|
queries.Assign(&b.WithdrawalCryptoID, a.ID)
|
|
queries.Assign(&c.WithdrawalCryptoID, 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.WithdrawalCryptoWithdrawalCryptos().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if queries.Equal(v.WithdrawalCryptoID, b.WithdrawalCryptoID) {
|
|
bFound = true
|
|
}
|
|
if queries.Equal(v.WithdrawalCryptoID, c.WithdrawalCryptoID) {
|
|
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.LoadWithdrawalCryptoWithdrawalCryptos(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.WithdrawalCryptoWithdrawalCryptos); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.WithdrawalCryptoWithdrawalCryptos = nil
|
|
if err = a.L.LoadWithdrawalCryptoWithdrawalCryptos(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.WithdrawalCryptoWithdrawalCryptos); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManyWithdrawalFiatWithdrawalFiats(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)
|
|
}
|
|
|
|
queries.Assign(&b.WithdrawalFiatID, a.ID)
|
|
queries.Assign(&c.WithdrawalFiatID, 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.WithdrawalFiatWithdrawalFiats().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if queries.Equal(v.WithdrawalFiatID, b.WithdrawalFiatID) {
|
|
bFound = true
|
|
}
|
|
if queries.Equal(v.WithdrawalFiatID, c.WithdrawalFiatID) {
|
|
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.LoadWithdrawalFiatWithdrawalFiats(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.WithdrawalFiatWithdrawalFiats); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.WithdrawalFiatWithdrawalFiats = nil
|
|
if err = a.L.LoadWithdrawalFiatWithdrawalFiats(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.WithdrawalFiatWithdrawalFiats); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManyAddOpWithdrawalCryptoWithdrawalCryptos(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.AddWithdrawalCryptoWithdrawalCryptos(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if !queries.Equal(a.ID, first.WithdrawalCryptoID) {
|
|
t.Error("foreign key was wrong value", a.ID, first.WithdrawalCryptoID)
|
|
}
|
|
if !queries.Equal(a.ID, second.WithdrawalCryptoID) {
|
|
t.Error("foreign key was wrong value", a.ID, second.WithdrawalCryptoID)
|
|
}
|
|
|
|
if first.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
if second.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.WithdrawalCryptoWithdrawalCryptos().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManySetOpWithdrawalCryptoWithdrawalCryptos(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)
|
|
}
|
|
|
|
err = a.SetWithdrawalCryptoWithdrawalCryptos(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.WithdrawalCryptoWithdrawalCryptos().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetWithdrawalCryptoWithdrawalCryptos(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.WithdrawalCryptoWithdrawalCryptos().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.WithdrawalCryptoID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.WithdrawalCryptoID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
if !queries.Equal(a.ID, d.WithdrawalCryptoID) {
|
|
t.Error("foreign key was wrong value", a.ID, d.WithdrawalCryptoID)
|
|
}
|
|
if !queries.Equal(a.ID, e.WithdrawalCryptoID) {
|
|
t.Error("foreign key was wrong value", a.ID, e.WithdrawalCryptoID)
|
|
}
|
|
|
|
if b.R.WithdrawalCrypto != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.WithdrawalCrypto != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManyRemoveOpWithdrawalCryptoWithdrawalCryptos(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)
|
|
}
|
|
|
|
err = a.AddWithdrawalCryptoWithdrawalCryptos(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.WithdrawalCryptoWithdrawalCryptos().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemoveWithdrawalCryptoWithdrawalCryptos(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.WithdrawalCryptoWithdrawalCryptos().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.WithdrawalCryptoID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.WithdrawalCryptoID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
|
|
if b.R.WithdrawalCrypto != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.WithdrawalCrypto != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
if e.R.WithdrawalCrypto != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
|
|
if len(a.R.WithdrawalCryptoWithdrawalCryptos) != 2 {
|
|
t.Error("should have preserved two relationships")
|
|
}
|
|
|
|
// Removal doesn't do a stable deletion for performance so we have to flip the order
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.WithdrawalCryptoWithdrawalCryptos[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManyAddOpWithdrawalFiatWithdrawalFiats(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.AddWithdrawalFiatWithdrawalFiats(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if !queries.Equal(a.ID, first.WithdrawalFiatID) {
|
|
t.Error("foreign key was wrong value", a.ID, first.WithdrawalFiatID)
|
|
}
|
|
if !queries.Equal(a.ID, second.WithdrawalFiatID) {
|
|
t.Error("foreign key was wrong value", a.ID, second.WithdrawalFiatID)
|
|
}
|
|
|
|
if first.R.WithdrawalFiat != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
if second.R.WithdrawalFiat != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
|
|
if a.R.WithdrawalFiatWithdrawalFiats[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.WithdrawalFiatWithdrawalFiats[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.WithdrawalFiatWithdrawalFiats().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManySetOpWithdrawalFiatWithdrawalFiats(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)
|
|
}
|
|
|
|
err = a.SetWithdrawalFiatWithdrawalFiats(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.WithdrawalFiatWithdrawalFiats().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetWithdrawalFiatWithdrawalFiats(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.WithdrawalFiatWithdrawalFiats().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.WithdrawalFiatID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.WithdrawalFiatID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
if !queries.Equal(a.ID, d.WithdrawalFiatID) {
|
|
t.Error("foreign key was wrong value", a.ID, d.WithdrawalFiatID)
|
|
}
|
|
if !queries.Equal(a.ID, e.WithdrawalFiatID) {
|
|
t.Error("foreign key was wrong value", a.ID, e.WithdrawalFiatID)
|
|
}
|
|
|
|
if b.R.WithdrawalFiat != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.WithdrawalFiat != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.WithdrawalFiat != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.WithdrawalFiat != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if a.R.WithdrawalFiatWithdrawalFiats[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.WithdrawalFiatWithdrawalFiats[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoryToManyRemoveOpWithdrawalFiatWithdrawalFiats(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)
|
|
}
|
|
|
|
err = a.AddWithdrawalFiatWithdrawalFiats(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.WithdrawalFiatWithdrawalFiats().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemoveWithdrawalFiatWithdrawalFiats(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.WithdrawalFiatWithdrawalFiats().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.WithdrawalFiatID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.WithdrawalFiatID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
|
|
if b.R.WithdrawalFiat != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.WithdrawalFiat != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.WithdrawalFiat != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
if e.R.WithdrawalFiat != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
|
|
if len(a.R.WithdrawalFiatWithdrawalFiats) != 2 {
|
|
t.Error("should have preserved two relationships")
|
|
}
|
|
|
|
// Removal doesn't do a stable deletion for performance so we have to flip the order
|
|
if a.R.WithdrawalFiatWithdrawalFiats[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.WithdrawalFiatWithdrawalFiats[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
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`: `uuid`, `Exchange`: `text`, `ExchangeID`: `text`, `Status`: `character varying`, `Currency`: `text`, `Amount`: `double precision`, `Description`: `text`, `WithdrawType`: `integer`, `CreatedAt`: `timestamp without time zone`, `UpdatedAt`: `timestamp without time zone`}
|
|
_ = 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)
|
|
}
|
|
}
|
|
|
|
func testWithdrawalHistoriesUpsert(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
|
|
// Attempt the INSERT side of an UPSERT
|
|
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.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
|
t.Errorf("Unable to upsert WithdrawalHistory: %s", err)
|
|
}
|
|
|
|
count, err := WithdrawalHistories().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
|
|
// Attempt the UPDATE side of an UPSERT
|
|
if err = randomize.Struct(seed, &o, withdrawalHistoryDBTypes, false, withdrawalHistoryPrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
|
}
|
|
|
|
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
|
t.Errorf("Unable to upsert WithdrawalHistory: %s", err)
|
|
}
|
|
|
|
count, err = WithdrawalHistories().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|