mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-15 15:09:55 +00:00
* Remove old concept. Introduce new job types and candle scaling * Adds extra processing, commands * new concept for queued jobs. Jobs can pause. New commands to manage status * =End of day commit designing tables and implementing prerequisites further. * Adds postgres data history relations * Fixes table design for sqlite. Fixes all issues from merge * Fixes craziness of database design. Adds some functions to get related jobs * Fixes errors * Updates some documentation, manages prerequisite jobs a little better, adds rpc funcs * Fixes database design and adjust repo functions * Tests database relationship * Test coverage of new job functions * Finishes coverage of new functions * Commands and RPC coverage * New database modifications for new job types * Adds db support of new columns. Adds conversion validation. lint * command blurb changes * Allows websocket test to pass consistently * Fixes merge issue preventing datahistorymanager from starting via config * Minor fixes for different job type processing * Fixes rangeholder issue, fixes validation, does not address jobs not starting or wrong status * Fixes database tests, but at what cost. Fixes dhm tests * Fixes dhj completion issue. Adds prerequisite by nickname * Fixes validation processing. Adds db tests and validation * Fixes validation job processing range * Fixes trade sql. Reduces defaults. Validation processing and errors * Updates cli job commands. adds validation decimal. fix job validation * Expands run job handling and tests * Validation work * Fixes validation processing * candle relations. new job type. updating database design * Adds secondary exchange support. Sets stage for candle override * Re adds accidentally deleted relationship * Updates loading and saving candles to have relationship data when relevant * Now validates and replaces candle data appropriately * Fixes getting and setting datahistory data. Neatens DHM * Test coverage * Updates proto for new db types. New test coverage. Secondary exchange work * Investigation into never-ending validation jobs. Now that intervals are ruled out, now need to complete the job.... * Fixes issues with validation job completion. Fixes validation volume issue for secondary exchange * Adds candle warning support to the backtester * Fixes warnings * lint and begin docs * Documentation updates. Final testing changes * Minor fixes * docs, prerequisite checks, more testing * Fixes binance trade test. Rename err * Documentation fixes. Figure fixes * documentation update * Fixes remote PSQL tests * Fix binance mock test * Remove unnecessary JSON * regen proto * Some minor nit fixes * Var usage, query sorting, log improving, sql mirroring * Extra coverage * Experimental removal of m.jobs and mutex. Fix messaging * Fixes error * Lint fixes, command description improvements. More isRunning gates * description improvements * Lint * BUFF regenerate * Rough concept to fix insertions taking up long periods of time * New calculation for trade data. Adds batch saving This also adds an experimental request feature to shut down lingering requests. However, its uncertain whether or not this is having any impact. Initially thought it was the trades that was taking time and not SQL. Will investigate further * Removes experimental requester. Adds documentation. Fixes typo * rm unused error * re-adds more forgotten contributors * Now with proper commit count
2434 lines
66 KiB
Go
2434 lines
66 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 testDatahistoryjobs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
query := Datahistoryjobs()
|
|
|
|
if query.Query == nil {
|
|
t.Error("expected a query, got nothing")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsDelete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsQueryDeleteAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().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 := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsSliceDeleteAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := DatahistoryjobSlice{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 := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 0 {
|
|
t.Error("want zero records, got:", count)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsExists(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := DatahistoryjobExists(ctx, tx, o.ID)
|
|
if err != nil {
|
|
t.Errorf("Unable to check if Datahistoryjob exists: %s", err)
|
|
}
|
|
if !e {
|
|
t.Errorf("Expected DatahistoryjobExists to return true, but got false.")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsFind(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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)
|
|
}
|
|
|
|
datahistoryjobFound, err := FindDatahistoryjob(ctx, tx, o.ID)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if datahistoryjobFound == nil {
|
|
t.Error("want a record, got nil")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsBind(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 = Datahistoryjobs().Bind(ctx, tx, o); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsOne(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().One(ctx, tx); err != nil {
|
|
t.Error(err)
|
|
} else if x == nil {
|
|
t.Error("expected to get a non nil record")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
datahistoryjobOne := &Datahistoryjob{}
|
|
datahistoryjobTwo := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, datahistoryjobOne, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
if err = randomize.Struct(seed, datahistoryjobTwo, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = datahistoryjobOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
if err = datahistoryjobTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
slice, err := Datahistoryjobs().All(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(slice) != 2 {
|
|
t.Error("want 2 records, got:", len(slice))
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsCount(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var err error
|
|
seed := randomize.NewSeed()
|
|
datahistoryjobOne := &Datahistoryjob{}
|
|
datahistoryjobTwo := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, datahistoryjobOne, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
if err = randomize.Struct(seed, datahistoryjobTwo, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = datahistoryjobOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
if err = datahistoryjobTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
count, err := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 2 {
|
|
t.Error("want 2 records, got:", count)
|
|
}
|
|
}
|
|
|
|
func datahistoryjobBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func datahistoryjobAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Datahistoryjob) error {
|
|
*o = Datahistoryjob{}
|
|
return nil
|
|
}
|
|
|
|
func testDatahistoryjobsHooks(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
empty := &Datahistoryjob{}
|
|
o := &Datahistoryjob{}
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, false); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob object: %s", err)
|
|
}
|
|
|
|
AddDatahistoryjobHook(boil.BeforeInsertHook, datahistoryjobBeforeInsertHook)
|
|
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)
|
|
}
|
|
datahistoryjobBeforeInsertHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.AfterInsertHook, datahistoryjobAfterInsertHook)
|
|
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)
|
|
}
|
|
datahistoryjobAfterInsertHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.AfterSelectHook, datahistoryjobAfterSelectHook)
|
|
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)
|
|
}
|
|
datahistoryjobAfterSelectHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.BeforeUpdateHook, datahistoryjobBeforeUpdateHook)
|
|
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)
|
|
}
|
|
datahistoryjobBeforeUpdateHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.AfterUpdateHook, datahistoryjobAfterUpdateHook)
|
|
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)
|
|
}
|
|
datahistoryjobAfterUpdateHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.BeforeDeleteHook, datahistoryjobBeforeDeleteHook)
|
|
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)
|
|
}
|
|
datahistoryjobBeforeDeleteHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.AfterDeleteHook, datahistoryjobAfterDeleteHook)
|
|
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)
|
|
}
|
|
datahistoryjobAfterDeleteHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.BeforeUpsertHook, datahistoryjobBeforeUpsertHook)
|
|
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)
|
|
}
|
|
datahistoryjobBeforeUpsertHooks = []DatahistoryjobHook{}
|
|
|
|
AddDatahistoryjobHook(boil.AfterUpsertHook, datahistoryjobAfterUpsertHook)
|
|
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)
|
|
}
|
|
datahistoryjobAfterUpsertHooks = []DatahistoryjobHook{}
|
|
}
|
|
|
|
func testDatahistoryjobsInsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsInsertWhitelist(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
if err = o.Insert(ctx, tx, boil.Whitelist(datahistoryjobColumnsWithoutDefault...)); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
count, err := Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManySourceJobCandles(t *testing.T) {
|
|
var err error
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = randomize.Struct(seed, &b, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
queries.Assign(&b.SourceJobID, a.ID)
|
|
queries.Assign(&c.SourceJobID, 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.SourceJobCandles().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if queries.Equal(v.SourceJobID, b.SourceJobID) {
|
|
bFound = true
|
|
}
|
|
if queries.Equal(v.SourceJobID, c.SourceJobID) {
|
|
cFound = true
|
|
}
|
|
}
|
|
|
|
if !bFound {
|
|
t.Error("expected to find b")
|
|
}
|
|
if !cFound {
|
|
t.Error("expected to find c")
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&a}
|
|
if err = a.L.LoadSourceJobCandles(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.SourceJobCandles); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.SourceJobCandles = nil
|
|
if err = a.L.LoadSourceJobCandles(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.SourceJobCandles); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyValidationJobCandles(t *testing.T) {
|
|
var err error
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = randomize.Struct(seed, &b, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
queries.Assign(&b.ValidationJobID, a.ID)
|
|
queries.Assign(&c.ValidationJobID, 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.ValidationJobCandles().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if queries.Equal(v.ValidationJobID, b.ValidationJobID) {
|
|
bFound = true
|
|
}
|
|
if queries.Equal(v.ValidationJobID, c.ValidationJobID) {
|
|
cFound = true
|
|
}
|
|
}
|
|
|
|
if !bFound {
|
|
t.Error("expected to find b")
|
|
}
|
|
if !cFound {
|
|
t.Error("expected to find c")
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&a}
|
|
if err = a.L.LoadValidationJobCandles(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.ValidationJobCandles); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.ValidationJobCandles = nil
|
|
if err = a.L.LoadValidationJobCandles(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.ValidationJobCandles); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyPrerequisiteJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = randomize.Struct(seed, &b, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); 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 = tx.Exec("insert into \"datahistoryjobrelations\" (\"job_id\", \"prerequisite_job_id\") values ($1, $2)", a.ID, b.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"job_id\", \"prerequisite_job_id\") values ($1, $2)", a.ID, c.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check, err := a.PrerequisiteJobDatahistoryjobs().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if v.ID == b.ID {
|
|
bFound = true
|
|
}
|
|
if v.ID == c.ID {
|
|
cFound = true
|
|
}
|
|
}
|
|
|
|
if !bFound {
|
|
t.Error("expected to find b")
|
|
}
|
|
if !cFound {
|
|
t.Error("expected to find c")
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&a}
|
|
if err = a.L.LoadPrerequisiteJobDatahistoryjobs(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.PrerequisiteJobDatahistoryjobs); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.PrerequisiteJobDatahistoryjobs = nil
|
|
if err = a.L.LoadPrerequisiteJobDatahistoryjobs(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.PrerequisiteJobDatahistoryjobs); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = randomize.Struct(seed, &b, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); 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 = tx.Exec("insert into \"datahistoryjobrelations\" (\"prerequisite_job_id\", \"job_id\") values ($1, $2)", a.ID, b.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = tx.Exec("insert into \"datahistoryjobrelations\" (\"prerequisite_job_id\", \"job_id\") values ($1, $2)", a.ID, c.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check, err := a.JobDatahistoryjobs().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if v.ID == b.ID {
|
|
bFound = true
|
|
}
|
|
if v.ID == c.ID {
|
|
cFound = true
|
|
}
|
|
}
|
|
|
|
if !bFound {
|
|
t.Error("expected to find b")
|
|
}
|
|
if !cFound {
|
|
t.Error("expected to find c")
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&a}
|
|
if err = a.L.LoadJobDatahistoryjobs(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.JobDatahistoryjobs); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.JobDatahistoryjobs = nil
|
|
if err = a.L.LoadJobDatahistoryjobs(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.JobDatahistoryjobs); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyJobDatahistoryjobresults(t *testing.T) {
|
|
var err error
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Datahistoryjobresult
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = randomize.Struct(seed, &b, datahistoryjobresultDBTypes, false, datahistoryjobresultColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &c, datahistoryjobresultDBTypes, false, datahistoryjobresultColumnsWithDefault...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
b.JobID = a.ID
|
|
c.JobID = 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.JobDatahistoryjobresults().All(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bFound, cFound := false, false
|
|
for _, v := range check {
|
|
if v.JobID == b.JobID {
|
|
bFound = true
|
|
}
|
|
if v.JobID == c.JobID {
|
|
cFound = true
|
|
}
|
|
}
|
|
|
|
if !bFound {
|
|
t.Error("expected to find b")
|
|
}
|
|
if !cFound {
|
|
t.Error("expected to find c")
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&a}
|
|
if err = a.L.LoadJobDatahistoryjobresults(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.JobDatahistoryjobresults); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
a.R.JobDatahistoryjobresults = nil
|
|
if err = a.L.LoadJobDatahistoryjobresults(ctx, tx, true, &a, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(a.R.JobDatahistoryjobresults); got != 2 {
|
|
t.Error("number of eager loaded records wrong, got:", got)
|
|
}
|
|
|
|
if t.Failed() {
|
|
t.Logf("%#v", check)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyAddOpSourceJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); 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 := [][]*Candle{
|
|
{&b, &c},
|
|
{&d, &e},
|
|
}
|
|
|
|
for i, x := range foreignersSplitByInsertion {
|
|
err = a.AddSourceJobCandles(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if !queries.Equal(a.ID, first.SourceJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, first.SourceJobID)
|
|
}
|
|
if !queries.Equal(a.ID, second.SourceJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, second.SourceJobID)
|
|
}
|
|
|
|
if first.R.SourceJob != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
if second.R.SourceJob != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
|
|
if a.R.SourceJobCandles[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.SourceJobCandles[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.SourceJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManySetOpSourceJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); 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.SetSourceJobCandles(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.SourceJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetSourceJobCandles(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.SourceJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.SourceJobID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.SourceJobID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
if !queries.Equal(a.ID, d.SourceJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, d.SourceJobID)
|
|
}
|
|
if !queries.Equal(a.ID, e.SourceJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, e.SourceJobID)
|
|
}
|
|
|
|
if b.R.SourceJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.SourceJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.SourceJob != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.SourceJob != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if a.R.SourceJobCandles[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.SourceJobCandles[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyRemoveOpSourceJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = a.AddSourceJobCandles(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.SourceJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemoveSourceJobCandles(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.SourceJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.SourceJobID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.SourceJobID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
|
|
if b.R.SourceJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.SourceJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.SourceJob != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
if e.R.SourceJob != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
|
|
if len(a.R.SourceJobCandles) != 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.SourceJobCandles[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.SourceJobCandles[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyAddOpValidationJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); 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 := [][]*Candle{
|
|
{&b, &c},
|
|
{&d, &e},
|
|
}
|
|
|
|
for i, x := range foreignersSplitByInsertion {
|
|
err = a.AddValidationJobCandles(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if !queries.Equal(a.ID, first.ValidationJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, first.ValidationJobID)
|
|
}
|
|
if !queries.Equal(a.ID, second.ValidationJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, second.ValidationJobID)
|
|
}
|
|
|
|
if first.R.ValidationJob != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
if second.R.ValidationJob != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
|
|
if a.R.ValidationJobCandles[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.ValidationJobCandles[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.ValidationJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManySetOpValidationJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); 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.SetValidationJobCandles(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.ValidationJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetValidationJobCandles(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.ValidationJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.ValidationJobID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.ValidationJobID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
if !queries.Equal(a.ID, d.ValidationJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, d.ValidationJobID)
|
|
}
|
|
if !queries.Equal(a.ID, e.ValidationJobID) {
|
|
t.Error("foreign key was wrong value", a.ID, e.ValidationJobID)
|
|
}
|
|
|
|
if b.R.ValidationJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.ValidationJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.ValidationJob != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.ValidationJob != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if a.R.ValidationJobCandles[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.ValidationJobCandles[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyRemoveOpValidationJobCandles(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Candle
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Candle{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = a.AddValidationJobCandles(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.ValidationJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemoveValidationJobCandles(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.ValidationJobCandles().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if !queries.IsValuerNil(b.ValidationJobID) {
|
|
t.Error("want b's foreign key value to be nil")
|
|
}
|
|
if !queries.IsValuerNil(c.ValidationJobID) {
|
|
t.Error("want c's foreign key value to be nil")
|
|
}
|
|
|
|
if b.R.ValidationJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if c.R.ValidationJob != nil {
|
|
t.Error("relationship was not removed properly from the foreign struct")
|
|
}
|
|
if d.R.ValidationJob != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
if e.R.ValidationJob != &a {
|
|
t.Error("relationship to a should have been preserved")
|
|
}
|
|
|
|
if len(a.R.ValidationJobCandles) != 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.ValidationJobCandles[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.ValidationJobCandles[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyAddOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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 := [][]*Datahistoryjob{
|
|
{&b, &c},
|
|
{&d, &e},
|
|
}
|
|
|
|
for i, x := range foreignersSplitByInsertion {
|
|
err = a.AddPrerequisiteJobDatahistoryjobs(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if first.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
if second.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
|
|
if a.R.PrerequisiteJobDatahistoryjobs[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.PrerequisiteJobDatahistoryjobs[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManySetOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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.SetPrerequisiteJobDatahistoryjobs(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetPrerequisiteJobDatahistoryjobs(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
// The following checks cannot be implemented since we have no handle
|
|
// to these when we call Set(). Leaving them here as wishful thinking
|
|
// and to let people know there's dragons.
|
|
//
|
|
// if len(b.R.JobDatahistoryjobs) != 0 {
|
|
// t.Error("relationship was not removed properly from the slice")
|
|
// }
|
|
// if len(c.R.JobDatahistoryjobs) != 0 {
|
|
// t.Error("relationship was not removed properly from the slice")
|
|
// }
|
|
if d.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
if e.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
|
|
if a.R.PrerequisiteJobDatahistoryjobs[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.PrerequisiteJobDatahistoryjobs[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyRemoveOpPrerequisiteJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = a.AddPrerequisiteJobDatahistoryjobs(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemovePrerequisiteJobDatahistoryjobs(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.PrerequisiteJobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if len(b.R.JobDatahistoryjobs) != 0 {
|
|
t.Error("relationship was not removed properly from the slice")
|
|
}
|
|
if len(c.R.JobDatahistoryjobs) != 0 {
|
|
t.Error("relationship was not removed properly from the slice")
|
|
}
|
|
if d.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.JobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if len(a.R.PrerequisiteJobDatahistoryjobs) != 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.PrerequisiteJobDatahistoryjobs[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.PrerequisiteJobDatahistoryjobs[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyAddOpJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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 := [][]*Datahistoryjob{
|
|
{&b, &c},
|
|
{&d, &e},
|
|
}
|
|
|
|
for i, x := range foreignersSplitByInsertion {
|
|
err = a.AddJobDatahistoryjobs(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if first.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
if second.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
|
|
if a.R.JobDatahistoryjobs[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.JobDatahistoryjobs[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.JobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManySetOpJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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.SetJobDatahistoryjobs(ctx, tx, false, &b, &c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.JobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.SetJobDatahistoryjobs(ctx, tx, true, &d, &e)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.JobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
// The following checks cannot be implemented since we have no handle
|
|
// to these when we call Set(). Leaving them here as wishful thinking
|
|
// and to let people know there's dragons.
|
|
//
|
|
// if len(b.R.PrerequisiteJobDatahistoryjobs) != 0 {
|
|
// t.Error("relationship was not removed properly from the slice")
|
|
// }
|
|
// if len(c.R.PrerequisiteJobDatahistoryjobs) != 0 {
|
|
// t.Error("relationship was not removed properly from the slice")
|
|
// }
|
|
if d.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
if e.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the slice")
|
|
}
|
|
|
|
if a.R.JobDatahistoryjobs[0] != &d {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.JobDatahistoryjobs[1] != &e {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyRemoveOpJobDatahistoryjobs(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjob
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = a.AddJobDatahistoryjobs(ctx, tx, true, foreigners...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err := a.JobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 4 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
err = a.RemoveJobDatahistoryjobs(ctx, tx, foreigners[:2]...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
count, err = a.JobDatahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 2 {
|
|
t.Error("count was wrong:", count)
|
|
}
|
|
|
|
if len(b.R.PrerequisiteJobDatahistoryjobs) != 0 {
|
|
t.Error("relationship was not removed properly from the slice")
|
|
}
|
|
if len(c.R.PrerequisiteJobDatahistoryjobs) != 0 {
|
|
t.Error("relationship was not removed properly from the slice")
|
|
}
|
|
if d.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
if e.R.PrerequisiteJobDatahistoryjobs[0] != &a {
|
|
t.Error("relationship was not added properly to the foreign struct")
|
|
}
|
|
|
|
if len(a.R.JobDatahistoryjobs) != 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.JobDatahistoryjobs[1] != &d {
|
|
t.Error("relationship to d should have been preserved")
|
|
}
|
|
if a.R.JobDatahistoryjobs[0] != &e {
|
|
t.Error("relationship to e should have been preserved")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToManyAddOpJobDatahistoryjobresults(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c, d, e Datahistoryjobresult
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
foreigners := []*Datahistoryjobresult{&b, &c, &d, &e}
|
|
for _, x := range foreigners {
|
|
if err = randomize.Struct(seed, x, datahistoryjobresultDBTypes, false, strmangle.SetComplement(datahistoryjobresultPrimaryKeyColumns, datahistoryjobresultColumnsWithoutDefault)...); 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 := [][]*Datahistoryjobresult{
|
|
{&b, &c},
|
|
{&d, &e},
|
|
}
|
|
|
|
for i, x := range foreignersSplitByInsertion {
|
|
err = a.AddJobDatahistoryjobresults(ctx, tx, i != 0, x...)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
first := x[0]
|
|
second := x[1]
|
|
|
|
if a.ID != first.JobID {
|
|
t.Error("foreign key was wrong value", a.ID, first.JobID)
|
|
}
|
|
if a.ID != second.JobID {
|
|
t.Error("foreign key was wrong value", a.ID, second.JobID)
|
|
}
|
|
|
|
if first.R.Job != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
if second.R.Job != &a {
|
|
t.Error("relationship was not added properly to the foreign slice")
|
|
}
|
|
|
|
if a.R.JobDatahistoryjobresults[i*2] != first {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
if a.R.JobDatahistoryjobresults[i*2+1] != second {
|
|
t.Error("relationship struct slice not set to correct value")
|
|
}
|
|
|
|
count, err := a.JobDatahistoryjobresults().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := int64((i + 1) * 2); count != want {
|
|
t.Error("want", want, "got", count)
|
|
}
|
|
}
|
|
}
|
|
func testDatahistoryjobToOneExchangeUsingExchangeName(t *testing.T) {
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var local Datahistoryjob
|
|
var foreign Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err := randomize.Struct(seed, &local, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := DatahistoryjobSlice{&local}
|
|
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Datahistoryjob)(&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 testDatahistoryjobToOneExchangeUsingSecondaryExchange(t *testing.T) {
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var local Datahistoryjob
|
|
var foreign Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err := randomize.Struct(seed, &local, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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)
|
|
}
|
|
|
|
queries.Assign(&local.SecondaryExchangeID, foreign.ID)
|
|
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check, err := local.SecondaryExchange().One(ctx, tx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !queries.Equal(check.ID, foreign.ID) {
|
|
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
|
}
|
|
|
|
slice := DatahistoryjobSlice{&local}
|
|
if err = local.L.LoadSecondaryExchange(ctx, tx, false, (*[]*Datahistoryjob)(&slice), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if local.R.SecondaryExchange == nil {
|
|
t.Error("struct should have been eager loaded")
|
|
}
|
|
|
|
local.R.SecondaryExchange = nil
|
|
if err = local.L.LoadSecondaryExchange(ctx, tx, true, &local, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if local.R.SecondaryExchange == nil {
|
|
t.Error("struct should have been eager loaded")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToOneSetOpExchangeUsingExchangeName(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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.ExchangeNameDatahistoryjobs[0] != &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 testDatahistoryjobToOneSetOpExchangeUsingSecondaryExchange(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b, c Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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.SetSecondaryExchange(ctx, tx, i != 0, x)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if a.R.SecondaryExchange != x {
|
|
t.Error("relationship struct not set to correct value")
|
|
}
|
|
|
|
if x.R.SecondaryExchangeDatahistoryjobs[0] != &a {
|
|
t.Error("failed to append to foreign relationship struct")
|
|
}
|
|
if !queries.Equal(a.SecondaryExchangeID, x.ID) {
|
|
t.Error("foreign key was wrong value", a.SecondaryExchangeID)
|
|
}
|
|
|
|
zero := reflect.Zero(reflect.TypeOf(a.SecondaryExchangeID))
|
|
reflect.Indirect(reflect.ValueOf(&a.SecondaryExchangeID)).Set(zero)
|
|
|
|
if err = a.Reload(ctx, tx); err != nil {
|
|
t.Fatal("failed to reload", err)
|
|
}
|
|
|
|
if !queries.Equal(a.SecondaryExchangeID, x.ID) {
|
|
t.Error("foreign key was wrong value", a.SecondaryExchangeID, x.ID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobToOneRemoveOpExchangeUsingSecondaryExchange(t *testing.T) {
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
tx := MustTx(boil.BeginTx(ctx, nil))
|
|
defer func() { _ = tx.Rollback() }()
|
|
|
|
var a Datahistoryjob
|
|
var b Exchange
|
|
|
|
seed := randomize.NewSeed()
|
|
if err = randomize.Struct(seed, &a, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = randomize.Struct(seed, &b, 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 = a.SetSecondaryExchange(ctx, tx, true, &b); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = a.RemoveSecondaryExchange(ctx, tx, &b); err != nil {
|
|
t.Error("failed to remove relationship")
|
|
}
|
|
|
|
count, err := a.SecondaryExchange().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if count != 0 {
|
|
t.Error("want no relationships remaining")
|
|
}
|
|
|
|
if a.R.SecondaryExchange != nil {
|
|
t.Error("R struct entry should be nil")
|
|
}
|
|
|
|
if !queries.IsValuerNil(a.SecondaryExchangeID) {
|
|
t.Error("foreign key value should be nil")
|
|
}
|
|
|
|
if len(b.R.SecondaryExchangeDatahistoryjobs) != 0 {
|
|
t.Error("failed to remove a from b's relationships")
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsReload(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 testDatahistoryjobsReloadAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := DatahistoryjobSlice{o}
|
|
|
|
if err = slice.ReloadAll(ctx, tx); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func testDatahistoryjobsSelect(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().All(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(slice) != 1 {
|
|
t.Error("want one record, got:", len(slice))
|
|
}
|
|
}
|
|
|
|
var (
|
|
datahistoryjobDBTypes = map[string]string{`ID`: `uuid`, `Nickname`: `character varying`, `ExchangeNameID`: `uuid`, `Asset`: `character varying`, `Base`: `character varying`, `Quote`: `character varying`, `StartTime`: `timestamp with time zone`, `EndTime`: `timestamp with time zone`, `DataType`: `double precision`, `Interval`: `double precision`, `RequestSize`: `double precision`, `MaxRetries`: `double precision`, `BatchCount`: `double precision`, `Status`: `double precision`, `Created`: `timestamp with time zone`, `ConversionInterval`: `double precision`, `OverwriteData`: `boolean`, `DecimalPlaceComparison`: `integer`, `SecondaryExchangeID`: `uuid`, `IssueTolerancePercentage`: `double precision`, `ReplaceOnIssue`: `boolean`}
|
|
_ = bytes.MinRead
|
|
)
|
|
|
|
func testDatahistoryjobsUpdate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if 0 == len(datahistoryjobPrimaryKeyColumns) {
|
|
t.Skip("Skipping table with no primary key columns")
|
|
}
|
|
if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
|
|
t.Skip("Skipping table with only primary key columns")
|
|
}
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().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, datahistoryjobDBTypes, true, datahistoryjobPrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 testDatahistoryjobsSliceUpdateAll(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
|
|
t.Skip("Skipping table with only primary key columns")
|
|
}
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
o := &Datahistoryjob{}
|
|
if err = randomize.Struct(seed, o, datahistoryjobDBTypes, true, datahistoryjobColumnsWithDefault...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 := Datahistoryjobs().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, datahistoryjobDBTypes, true, datahistoryjobPrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
// Remove Primary keys and unique columns from what we plan to update
|
|
var fields []string
|
|
if strmangle.StringSliceMatch(datahistoryjobAllColumns, datahistoryjobPrimaryKeyColumns) {
|
|
fields = datahistoryjobAllColumns
|
|
} else {
|
|
fields = strmangle.SetComplement(
|
|
datahistoryjobAllColumns,
|
|
datahistoryjobPrimaryKeyColumns,
|
|
)
|
|
}
|
|
|
|
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 := DatahistoryjobSlice{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 testDatahistoryjobsUpsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if len(datahistoryjobAllColumns) == len(datahistoryjobPrimaryKeyColumns) {
|
|
t.Skip("Skipping table with only primary key columns")
|
|
}
|
|
|
|
seed := randomize.NewSeed()
|
|
var err error
|
|
// Attempt the INSERT side of an UPSERT
|
|
o := Datahistoryjob{}
|
|
if err = randomize.Struct(seed, &o, datahistoryjobDBTypes, true); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob 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 Datahistoryjob: %s", err)
|
|
}
|
|
|
|
count, err := Datahistoryjobs().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, datahistoryjobDBTypes, false, datahistoryjobPrimaryKeyColumns...); err != nil {
|
|
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
|
|
}
|
|
|
|
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
|
t.Errorf("Unable to upsert Datahistoryjob: %s", err)
|
|
}
|
|
|
|
count, err = Datahistoryjobs().Count(ctx, tx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if count != 1 {
|
|
t.Error("want one record, got:", count)
|
|
}
|
|
}
|