mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 15:09:51 +00:00
* WIP * end of day WIP started migration of trade history * added kline support to hitbtc huobi lbank * added exchangehistory to all supported exchanges started work on coinbase 300 candles/request method * end of day WIP * removed unused ta and misc changes to flag ready for review * yobit cleanup * revert coinbase changES * general code clean up and added zb support * poloniex support added * renamed method to FormatExchangeKlineInterval other misc fixes * linter fixes * linter fixes * removed verbose * fixed poloniex test coverage * revert poloniex mock data * regenerated poloniex mock data * a very verbose clean up * binance mock clean up * removed unneeded t.Log() * setting verbose to true to debug CI issue * first pass changes addressed * common.ErrNotYetImplemented implemented :D * comments added * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * increased test coverage added kraken support * OKGroup support completed started work on address GetExchangeHistory feedback and migrating to own PR under https://github.com/xtda/gocryptotrader/tree/exchange_history * convert zb ratelimits * gofmt run on okcoin * increased delay on rate limit * gofmt package * fixed panic with coinbene and bithumb if conversion fails * very broken end of day WIP * added support for GetHistoricCandlesEx to coinbase and binance * gofmt package * coinbase, btcmarkets, zb ex wrapper function added * added all exchange support for ex regenerated mock data * update bithumb to return wrapper method * gofmt package * end of day started work on changes * models created for exchange/asset/currency/currencypair, new seed system created * reworked test coverage added okgroup support general fixes/change requests addressed * Added OneMonth * limit checks on supportedexchanges * reverted getexchangehistory * started work on currency seeding and insertion * reworked binance tesT * added workaround for kraken panic * :D extremely broken WIP * renamed command to extended removed interval check on non-implemented commands * added wrapperconfig back * increased test coverage for FormatExchangeKlineInterval * WIP * increased test coverage for FormatExchangeKlineInterval bitfinex/gateio/huobi * linter fixes * zb kraken lbank coinbene btcmarkets support added * removed verbose * OK group support for other asset types added * swapped margin to use spot endpoint * index support added test coverage added for asset types * added asset type to okcoin test * gofmt * add asset to extended method * removed verbose * Very broken WIP models need to be regenerated * add support for coinbene swap increase test coverage * removed verbose * small clean up of okgroup wrapper functions * verbose to troubleshoot CI issues * removed verbose * added error check reverted coinbasechanges * attempting to fix broken model generation * readme updated * :D i broke so much * model regeneration fixed & complete * candle model filled out * removed unused start/finish started work on decoupling api requests from kline package * restructured coinbene, bithumb methods, added bitstamp support * kraken time fix * BTCMarkets restructure * typo fix * removed test for futures due to contact changing * removed test for futures due to contact changing * added start/end date to extended method over range * WIP * added sync option to candles * converted to assettranslator * removed verbose * removed verbose * removed invalid char * reverted incorrectly removed return * added import * further template updates * macos hates my keyboard :D * misc canges * started work on creating kline from databases eed * x -> i * removed verbose * updated fixCasing to allocate var before checks * sqlite3 supported work started * removed time conversion * further work on tets * sort all outgoing kline candles * fixCasing fix * after/before checks added * added parallel to test * logic check on BTCmarkets * removed unused param, used correct iterator * converted HitBTC to use time.Time * test update * add iszero false check to candle times * Seed exchange & OHCLV data for test usage * updated resultlimit to 5000 * new line added * added comment to exported const * move date forward * use configured ratelimit * fixed pair for test * panic fixed WIP on fixCasing * fixCasing rework, started work on readme docs * enable rate limiter for wrapper issues tool * docs updated * removed unused vars from tests * removed err from return and formatted currency * updated Yobit supported status * Updated HitBTC to use onehour candles due to test exeuction times * added further details to gctcli output * added link to docs * added link to tempalte * disable FTX websocket in config_example * fix poloneix * regenerated poloniex mock data * removed recording flag * format on package * moved exchange var outside of method scope * reworked seeding into package * verbose output improved * removed verbose from candles * Added comments to exported functions * removed verbose output * Reworking of tests * end of day commit * added SQLite migration for asset, test updates for exchange, added support for withdrawal for new exchange_name_id relation * regenerated database models * WIP * test rework, sqlite migration updates for withdrawal * Reworked error returns to stop duplications, format all output to UTC, changed gctscript OHLCV output to be unix timestmap, started work on seeding tool * gofmt * dbseed command for seeding exchanges added, removed seed from dbmigrate, LoadCSV method added for exchange * go mod tidy * added import candle from csv command to dbseed * Removed reset & duplicate migrate command from helper, renamed struct to Item/Candle over Candle/Tick, added test coverage to dbseed, improved withdraw tests * remove broken tests due to ORM generation of Fk, removed go unneeded goroutine for inserting records * removed t.Cleanup usage because appveyor * added test coverage to StoreInDatabase() * removed unneeded data from config for test * added new line * Added down migration support to candle/asset removal, return original error and display rollback error * removed unneeded err assignment, break out of loop on error * add err check to method for test * first pass changes * WIP * Updated migrations for both sqlite3 & postgres to create exchanges if any withdrawal_history records are found, removed migrate command * removed argusage as usage information is provided by flags * added inserted records return count and test coverage * new line added * Database: comment config details out to disable local postgresl testing by default * added asset support * Database: added error return when no exchanges are found, title exchange name across queries * Fixed test data * Database: removed migration bool from ConnectToDatabase(), removed empty line, insert asset on test * Database: verbose linter :D * Database/OHLCV: removed go module from dbseed command and reverted back to main module, converted interval to int64 to match other parts of code base, provided migrations to update database, poloniex fix to skip first candle * dbseed: add completed message to output * Database: added migration to add asset to uniq index for candle table * Database: database -> exchange * Database: add asset to upsert conflict * Poloneix: fix for invalid interval * regenerated poloniex mock data * Database: added down migration for candle interval update * OHCLV/Database: WIP * OHLCV/Datastore: added new ValidateKline() method to check that asset, pair, interval are enabled/supported by exchange and updated tests * revert configtest changes * OHCLV/Kline: pointer assignment to ErrorKline & format pairs on check * goimports * migration updates * Database/Candle: updated tests * revert configtest changes * ZB: updaed defaults to use uppercase pairs * ZB: updaed defaults to use uppercase pairs * revert pair formatting * Switch over to .Cotains() method from pairManagement * Added comment & ftx back 😆 * OHLCV/Datastore: (Candles): added not null to asset, (WithdrawalHistory): added not null to exchange_name_id), reworked KlineError return * set verbose to false * updated btc markets test * Updated readme * removed ability to have blank exchange name as indexing requires it * remove old usedb and empty exchange check, return error on no data instead * Updated kline test to match date range * Renamed candles.exchange_id column to candles.xchange_name_id to match withdrawal table, return err on unwrap, zb fix revert * regenerated sqlite3 models * force UTC for sqlite.... because sqlite * OHLCV/Datastore: upper case pairs on insert for consistency, remove unneeded rollback call on commit failure as it has no effect, move rollback outside of insertsqlite/insertpsql methods * add error check for no candles * nil length/cap is 0 in golang :D * OHLCV/Datastore: updated wording on examples, removed duplicate testfile * OHLCV/Datastore: updated README with links to dbseed * dbtool -> dbseed
794 lines
20 KiB
Go
794 lines
20 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 testCandles(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
query := Candles()
|
|
|
|
if query.Query == nil {
|
|
t.Error("expected a query, got nothing")
|
|
}
|
|
}
|
|
|
|
func testCandlesDelete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testCandlesQueryDeleteAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().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 := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testCandlesSliceDeleteAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := CandleSlice{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 := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testCandlesExists(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := CandleExists(ctx, tx, o.ID)
|
|
if err != nil {
|
|
t.Errorf("Unable to check if Candle exists: %s", err)
|
|
}
|
|
if !e {
|
|
t.Errorf("Expected CandleExists to return true, but got false.")
|
|
}
|
|
}
|
|
|
|
func testCandlesFind(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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)
|
|
}
|
|
|
|
candleFound, err := FindCandle(ctx, tx, o.ID)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if candleFound == nil {
|
|
t.Error("want a record, got nil")
|
|
}
|
|
}
|
|
|
|
func testCandlesBind(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 = Candles().Bind(ctx, tx, o); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func testCandlesOne(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().One(ctx, tx); err != nil {
|
|
t.Error(err)
|
|
} else if x == nil {
|
|
t.Error("expected to get a non nil record")
|
|
}
|
|
}
|
|
|
|
func testCandlesAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
candleOne := &Candle{}
|
|
candleTwo := &Candle{}
|
|
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
slice, err := Candles().All(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(slice) != 2 {
|
|
t.Error("want 2 records, got:", len(slice))
|
|
}
|
|
}
|
|
|
|
func testCandlesCount(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var err error
|
|
seed := randomize.NewSeed()
|
|
candleOne := &Candle{}
|
|
candleTwo := &Candle{}
|
|
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
count, err := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 2 {
|
|
t.Error("want 2 records, got:", count)
|
|
}
|
|
}
|
|
|
|
func candleBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func candleAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
|
*o = Candle{}
|
|
return nil
|
|
}
|
|
|
|
func testCandlesHooks(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
empty := &Candle{}
|
|
o := &Candle{}
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, o, candleDBTypes, false); err != nil {
|
|
t.Errorf("Unable to randomize Candle object: %s", err)
|
|
}
|
|
|
|
AddCandleHook(boil.BeforeInsertHook, candleBeforeInsertHook)
|
|
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)
|
|
}
|
|
candleBeforeInsertHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.AfterInsertHook, candleAfterInsertHook)
|
|
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)
|
|
}
|
|
candleAfterInsertHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.AfterSelectHook, candleAfterSelectHook)
|
|
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)
|
|
}
|
|
candleAfterSelectHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.BeforeUpdateHook, candleBeforeUpdateHook)
|
|
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)
|
|
}
|
|
candleBeforeUpdateHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.AfterUpdateHook, candleAfterUpdateHook)
|
|
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)
|
|
}
|
|
candleAfterUpdateHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.BeforeDeleteHook, candleBeforeDeleteHook)
|
|
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)
|
|
}
|
|
candleBeforeDeleteHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.AfterDeleteHook, candleAfterDeleteHook)
|
|
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)
|
|
}
|
|
candleAfterDeleteHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.BeforeUpsertHook, candleBeforeUpsertHook)
|
|
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)
|
|
}
|
|
candleBeforeUpsertHooks = []CandleHook{}
|
|
|
|
AddCandleHook(boil.AfterUpsertHook, candleAfterUpsertHook)
|
|
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)
|
|
}
|
|
candleAfterUpsertHooks = []CandleHook{}
|
|
}
|
|
|
|
func testCandlesInsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|
|
|
|
func testCandlesInsertWhitelist(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = o.Insert(ctx, tx, boil.Whitelist(candleColumnsWithoutDefault...)); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
count, err := Candles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|
|
|
|
func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var local Candle
|
|
var foreign Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err := randomize.Struct(seed, &local, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
|
}
|
|
|
|
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
local.ExchangeNameID = foreign.ID
|
|
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check, err := local.ExchangeName().One(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if check.ID != foreign.ID {
|
|
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
|
}
|
|
|
|
slice := CandleSlice{&local}
|
|
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if local.R.ExchangeName == nil {
|
|
t.Error("struct should have been eager loaded")
|
|
}
|
|
|
|
local.R.ExchangeName = nil
|
|
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if local.R.ExchangeName == nil {
|
|
t.Error("struct should have been eager loaded")
|
|
}
|
|
}
|
|
|
|
func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Candle
|
|
var b, c Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); 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)
|
|
}
|
|
|
|
for i, x := range []*Exchange{&b, &c} {
|
|
err = a.SetExchangeName(ctx, tx, i != 0, x)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if a.R.ExchangeName != x {
|
|
t.Error("relationship struct not set to correct value")
|
|
}
|
|
|
|
if x.R.ExchangeNameCandle != &a {
|
|
t.Error("failed to append to foreign relationship struct")
|
|
}
|
|
if a.ExchangeNameID != x.ID {
|
|
t.Error("foreign key was wrong value", a.ExchangeNameID)
|
|
}
|
|
|
|
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
|
|
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
|
|
|
|
if err = a.Reload(ctx, tx); err != nil {
|
|
t.Fatal("failed to reload", err)
|
|
}
|
|
|
|
if a.ExchangeNameID != x.ID {
|
|
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testCandlesReload(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 testCandlesReloadAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := CandleSlice{o}
|
|
|
|
if err = slice.ReloadAll(ctx, tx); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func testCandlesSelect(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().All(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(slice) != 1 {
|
|
t.Error("want one record, got:", len(slice))
|
|
}
|
|
}
|
|
|
|
var (
|
|
candleDBTypes = map[string]string{`ID`: `TEXT`, `ExchangeNameID`: `UUID`, `Base`: `TEXT`, `Quote`: `TEXT`, `Interval`: `TEXT`, `Timestamp`: `TIMESTAMP`, `Open`: `REAL`, `High`: `REAL`, `Low`: `REAL`, `Close`: `REAL`, `Volume`: `REAL`, `Asset`: `TEXT`}
|
|
_ = bytes.MinRead
|
|
)
|
|
|
|
func testCandlesUpdate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if 0 == len(candlePrimaryKeyColumns) {
|
|
t.Skip("Skipping table with no primary key columns")
|
|
}
|
|
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
|
|
t.Skip("Skipping table with only primary key columns")
|
|
}
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().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, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 testCandlesSliceUpdateAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
|
|
t.Skip("Skipping table with only primary key columns")
|
|
}
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Candle{}
|
|
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Candle 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 := Candles().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, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize Candle struct: %s", err)
|
|
}
|
|
|
|
// Remove Primary keys and unique columns from what we plan to update
|
|
var fields []string
|
|
if strmangle.StringSliceMatch(candleAllColumns, candlePrimaryKeyColumns) {
|
|
fields = candleAllColumns
|
|
} else {
|
|
fields = strmangle.SetComplement(
|
|
candleAllColumns,
|
|
candlePrimaryKeyColumns,
|
|
)
|
|
}
|
|
|
|
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 := CandleSlice{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)
|
|
}
|
|
}
|