From 1a160b613f19d4f64fb6c75f56aa19987a8c8f8b Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Fri, 7 Jan 2022 21:02:35 +0100 Subject: [PATCH] refactor: Disable autogenerated tests from SQLBoiler and switch to upstream driver --- Hydrunfile | 2 +- Makefile | 2 +- configs/sqlboiler/metadata.yaml | 1 + .../sqlite/models/metadata/boil_main_test.go | 119 --- .../models/metadata/boil_queries_test.go | 52 -- .../models/metadata/boil_suites_test.go | 139 ---- .../models/metadata/gorp_migrations_test.go | 731 ------------------ .../db/sqlite/models/metadata/headers_test.go | 731 ------------------ .../models/metadata/sqlite3_main_test.go | 93 --- .../models/metadata/sqlite3_suites_test.go | 12 - 10 files changed, 3 insertions(+), 1879 deletions(-) delete mode 100644 internal/db/sqlite/models/metadata/boil_main_test.go delete mode 100644 internal/db/sqlite/models/metadata/boil_queries_test.go delete mode 100644 internal/db/sqlite/models/metadata/boil_suites_test.go delete mode 100644 internal/db/sqlite/models/metadata/gorp_migrations_test.go delete mode 100644 internal/db/sqlite/models/metadata/headers_test.go delete mode 100644 internal/db/sqlite/models/metadata/sqlite3_main_test.go delete mode 100644 internal/db/sqlite/models/metadata/sqlite3_suites_test.go diff --git a/Hydrunfile b/Hydrunfile index 97f23b6..e9680a3 100755 --- a/Hydrunfile +++ b/Hydrunfile @@ -4,7 +4,7 @@ set -e # Install native dependencies apt update -apt install -y curl git +apt install -y curl # Install bagop curl -L -o /tmp/bagop "https://github.com/pojntfx/bagop/releases/latest/download/bagop.linux-$(uname -m)" diff --git a/Makefile b/Makefile index 581f6fe..f31b748 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ clean: depend: go install github.com/rubenv/sql-migrate/sql-migrate@latest go install github.com/volatiletech/sqlboiler/v4@latest - rm -rf /tmp/sqlboiler-sqlite3 && git clone https://github.com/pojntfx/sqlboiler-sqlite3 /tmp/sqlboiler-sqlite3 && cd /tmp/sqlboiler-sqlite3 && go install ./... + go install github.com/volatiletech/sqlboiler-sqlite3@latest go install github.com/jteeuwen/go-bindata/go-bindata@latest sql-migrate up -env="production" -config configs/sql-migrate/metadata.yaml go generate ./... \ No newline at end of file diff --git a/configs/sqlboiler/metadata.yaml b/configs/sqlboiler/metadata.yaml index bbf7e3b..2cd21ac 100644 --- a/configs/sqlboiler/metadata.yaml +++ b/configs/sqlboiler/metadata.yaml @@ -1,2 +1,3 @@ +no-tests: true sqlite3: dbname: /tmp/stfs-metadata.sqlite diff --git a/internal/db/sqlite/models/metadata/boil_main_test.go b/internal/db/sqlite/models/metadata/boil_main_test.go deleted file mode 100644 index 31dda3f..0000000 --- a/internal/db/sqlite/models/metadata/boil_main_test.go +++ /dev/null @@ -1,119 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "database/sql" - "flag" - "fmt" - "math/rand" - "os" - "path/filepath" - "strings" - "testing" - "time" - - "github.com/spf13/viper" - "github.com/volatiletech/sqlboiler/v4/boil" -) - -var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements") -var flagConfigFile = flag.String("test.config", "", "Overrides the default config") - -const outputDirDepth = 7 - -var ( - dbMain tester -) - -type tester interface { - setup() error - conn() (*sql.DB, error) - teardown() error -} - -func TestMain(m *testing.M) { - if dbMain == nil { - fmt.Println("no dbMain tester interface was ready") - os.Exit(-1) - } - - rand.Seed(time.Now().UnixNano()) - - flag.Parse() - - var err error - - // Load configuration - err = initViper() - if err != nil { - fmt.Println("unable to load config file") - os.Exit(-2) - } - - // Set DebugMode so we can see generated sql statements - boil.DebugMode = *flagDebugMode - - if err = dbMain.setup(); err != nil { - fmt.Println("Unable to execute setup:", err) - os.Exit(-4) - } - - conn, err := dbMain.conn() - if err != nil { - fmt.Println("failed to get connection:", err) - } - - var code int - boil.SetDB(conn) - code = m.Run() - - if err = dbMain.teardown(); err != nil { - fmt.Println("Unable to execute teardown:", err) - os.Exit(-5) - } - - os.Exit(code) -} - -func initViper() error { - if flagConfigFile != nil && *flagConfigFile != "" { - viper.SetConfigFile(*flagConfigFile) - if err := viper.ReadInConfig(); err != nil { - return err - } - return nil - } - - var err error - - viper.SetConfigName("sqlboiler") - - configHome := os.Getenv("XDG_CONFIG_HOME") - homePath := os.Getenv("HOME") - wd, err := os.Getwd() - if err != nil { - wd = strings.Repeat("../", outputDirDepth) - } else { - wd = wd + strings.Repeat("/..", outputDirDepth) - } - - configPaths := []string{wd} - if len(configHome) > 0 { - configPaths = append(configPaths, filepath.Join(configHome, "sqlboiler")) - } else { - configPaths = append(configPaths, filepath.Join(homePath, ".config/sqlboiler")) - } - - for _, p := range configPaths { - viper.AddConfigPath(p) - } - - // Ignore errors here, fall back to defaults and validation to provide errs - _ = viper.ReadInConfig() - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.AutomaticEnv() - - return nil -} diff --git a/internal/db/sqlite/models/metadata/boil_queries_test.go b/internal/db/sqlite/models/metadata/boil_queries_test.go deleted file mode 100644 index 9b856e3..0000000 --- a/internal/db/sqlite/models/metadata/boil_queries_test.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "math/rand" - "regexp" - - "github.com/volatiletech/sqlboiler/v4/boil" -) - -var dbNameRand *rand.Rand - -func MustTx(transactor boil.ContextTransactor, err error) boil.ContextTransactor { - if err != nil { - panic(fmt.Sprintf("Cannot create a transactor: %s", err)) - } - return transactor -} - -func newFKeyDestroyer(regex *regexp.Regexp, reader io.Reader) io.Reader { - return &fKeyDestroyer{ - reader: reader, - rgx: regex, - } -} - -type fKeyDestroyer struct { - reader io.Reader - buf *bytes.Buffer - rgx *regexp.Regexp -} - -func (f *fKeyDestroyer) Read(b []byte) (int, error) { - if f.buf == nil { - all, err := ioutil.ReadAll(f.reader) - if err != nil { - return 0, err - } - - all = bytes.Replace(all, []byte{'\r', '\n'}, []byte{'\n'}, -1) - all = f.rgx.ReplaceAll(all, []byte{}) - f.buf = bytes.NewBuffer(all) - } - - return f.buf.Read(b) -} diff --git a/internal/db/sqlite/models/metadata/boil_suites_test.go b/internal/db/sqlite/models/metadata/boil_suites_test.go deleted file mode 100644 index 77db085..0000000 --- a/internal/db/sqlite/models/metadata/boil_suites_test.go +++ /dev/null @@ -1,139 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import "testing" - -// This test suite runs each operation test in parallel. -// Example, if your database has 3 tables, the suite will run: -// table1, table2 and table3 Delete in parallel -// table1, table2 and table3 Insert in parallel, and so forth. -// It does NOT run each operation group in parallel. -// Separating the tests thusly grants avoidance of Postgres deadlocks. -func TestParent(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrations) - t.Run("Headers", testHeaders) -} - -func TestDelete(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsDelete) - t.Run("Headers", testHeadersDelete) -} - -func TestQueryDeleteAll(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsQueryDeleteAll) - t.Run("Headers", testHeadersQueryDeleteAll) -} - -func TestSliceDeleteAll(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsSliceDeleteAll) - t.Run("Headers", testHeadersSliceDeleteAll) -} - -func TestExists(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsExists) - t.Run("Headers", testHeadersExists) -} - -func TestFind(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsFind) - t.Run("Headers", testHeadersFind) -} - -func TestBind(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsBind) - t.Run("Headers", testHeadersBind) -} - -func TestOne(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsOne) - t.Run("Headers", testHeadersOne) -} - -func TestAll(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsAll) - t.Run("Headers", testHeadersAll) -} - -func TestCount(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsCount) - t.Run("Headers", testHeadersCount) -} - -func TestHooks(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsHooks) - t.Run("Headers", testHeadersHooks) -} - -func TestInsert(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsInsert) - t.Run("GorpMigrations", testGorpMigrationsInsertWhitelist) - t.Run("Headers", testHeadersInsert) - t.Run("Headers", testHeadersInsertWhitelist) -} - -// TestToOne tests cannot be run in parallel -// or deadlocks can occur. -func TestToOne(t *testing.T) {} - -// TestOneToOne tests cannot be run in parallel -// or deadlocks can occur. -func TestOneToOne(t *testing.T) {} - -// TestToMany tests cannot be run in parallel -// or deadlocks can occur. -func TestToMany(t *testing.T) {} - -// TestToOneSet tests cannot be run in parallel -// or deadlocks can occur. -func TestToOneSet(t *testing.T) {} - -// TestToOneRemove tests cannot be run in parallel -// or deadlocks can occur. -func TestToOneRemove(t *testing.T) {} - -// TestOneToOneSet tests cannot be run in parallel -// or deadlocks can occur. -func TestOneToOneSet(t *testing.T) {} - -// TestOneToOneRemove tests cannot be run in parallel -// or deadlocks can occur. -func TestOneToOneRemove(t *testing.T) {} - -// TestToManyAdd tests cannot be run in parallel -// or deadlocks can occur. -func TestToManyAdd(t *testing.T) {} - -// TestToManySet tests cannot be run in parallel -// or deadlocks can occur. -func TestToManySet(t *testing.T) {} - -// TestToManyRemove tests cannot be run in parallel -// or deadlocks can occur. -func TestToManyRemove(t *testing.T) {} - -func TestReload(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsReload) - t.Run("Headers", testHeadersReload) -} - -func TestReloadAll(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsReloadAll) - t.Run("Headers", testHeadersReloadAll) -} - -func TestSelect(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsSelect) - t.Run("Headers", testHeadersSelect) -} - -func TestUpdate(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsUpdate) - t.Run("Headers", testHeadersUpdate) -} - -func TestSliceUpdateAll(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsSliceUpdateAll) - t.Run("Headers", testHeadersSliceUpdateAll) -} diff --git a/internal/db/sqlite/models/metadata/gorp_migrations_test.go b/internal/db/sqlite/models/metadata/gorp_migrations_test.go deleted file mode 100644 index 7937fe2..0000000 --- a/internal/db/sqlite/models/metadata/gorp_migrations_test.go +++ /dev/null @@ -1,731 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "bytes" - "context" - "reflect" - "testing" - - "github.com/volatiletech/randomize" - "github.com/volatiletech/sqlboiler/v4/boil" - "github.com/volatiletech/sqlboiler/v4/queries" - "github.com/volatiletech/strmangle" -) - -func testGorpMigrationsUpsert(t *testing.T) { - t.Parallel() - if len(gorpMigrationAllColumns) == len(gorpMigrationPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - // Attempt the INSERT side of an UPSERT - o := GorpMigration{} - if err = randomize.Struct(seed, &o, gorpMigrationDBTypes, true); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 GorpMigration: %s", err) - } - - count, err := GorpMigrations().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, gorpMigrationDBTypes, false, gorpMigrationPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - - if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { - t.Errorf("Unable to upsert GorpMigration: %s", err) - } - - count, err = GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - if count != 1 { - t.Error("want one record, got:", count) - } -} - -var ( - // Relationships sometimes use the reflection helper queries.Equal/queries.Assign - // so force a package dependency in case they don't. - _ = queries.Equal -) - -func testGorpMigrations(t *testing.T) { - t.Parallel() - - query := GorpMigrations() - - if query.Query == nil { - t.Error("expected a query, got nothing") - } -} - -func testGorpMigrationsDelete(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testGorpMigrationsQueryDeleteAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().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 := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testGorpMigrationsSliceDeleteAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrationSlice{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 := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testGorpMigrationsExists(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrationExists(ctx, tx, o.ID) - if err != nil { - t.Errorf("Unable to check if GorpMigration exists: %s", err) - } - if !e { - t.Errorf("Expected GorpMigrationExists to return true, but got false.") - } -} - -func testGorpMigrationsFind(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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) - } - - gorpMigrationFound, err := FindGorpMigration(ctx, tx, o.ID) - if err != nil { - t.Error(err) - } - - if gorpMigrationFound == nil { - t.Error("want a record, got nil") - } -} - -func testGorpMigrationsBind(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 = GorpMigrations().Bind(ctx, tx, o); err != nil { - t.Error(err) - } -} - -func testGorpMigrationsOne(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().One(ctx, tx); err != nil { - t.Error(err) - } else if x == nil { - t.Error("expected to get a non nil record") - } -} - -func testGorpMigrationsAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - gorpMigrationOne := &GorpMigration{} - gorpMigrationTwo := &GorpMigration{} - if err = randomize.Struct(seed, gorpMigrationOne, gorpMigrationDBTypes, false, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - if err = randomize.Struct(seed, gorpMigrationTwo, gorpMigrationDBTypes, false, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = gorpMigrationOne.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - if err = gorpMigrationTwo.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - - slice, err := GorpMigrations().All(ctx, tx) - if err != nil { - t.Error(err) - } - - if len(slice) != 2 { - t.Error("want 2 records, got:", len(slice)) - } -} - -func testGorpMigrationsCount(t *testing.T) { - t.Parallel() - - var err error - seed := randomize.NewSeed() - gorpMigrationOne := &GorpMigration{} - gorpMigrationTwo := &GorpMigration{} - if err = randomize.Struct(seed, gorpMigrationOne, gorpMigrationDBTypes, false, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - if err = randomize.Struct(seed, gorpMigrationTwo, gorpMigrationDBTypes, false, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = gorpMigrationOne.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - if err = gorpMigrationTwo.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - - count, err := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 2 { - t.Error("want 2 records, got:", count) - } -} - -func gorpMigrationBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func gorpMigrationAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *GorpMigration) error { - *o = GorpMigration{} - return nil -} - -func testGorpMigrationsHooks(t *testing.T) { - t.Parallel() - - var err error - - ctx := context.Background() - empty := &GorpMigration{} - o := &GorpMigration{} - - seed := randomize.NewSeed() - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, false); err != nil { - t.Errorf("Unable to randomize GorpMigration object: %s", err) - } - - AddGorpMigrationHook(boil.BeforeInsertHook, gorpMigrationBeforeInsertHook) - 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) - } - gorpMigrationBeforeInsertHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.AfterInsertHook, gorpMigrationAfterInsertHook) - 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) - } - gorpMigrationAfterInsertHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.AfterSelectHook, gorpMigrationAfterSelectHook) - 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) - } - gorpMigrationAfterSelectHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.BeforeUpdateHook, gorpMigrationBeforeUpdateHook) - 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) - } - gorpMigrationBeforeUpdateHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.AfterUpdateHook, gorpMigrationAfterUpdateHook) - 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) - } - gorpMigrationAfterUpdateHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.BeforeDeleteHook, gorpMigrationBeforeDeleteHook) - 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) - } - gorpMigrationBeforeDeleteHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.AfterDeleteHook, gorpMigrationAfterDeleteHook) - 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) - } - gorpMigrationAfterDeleteHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.BeforeUpsertHook, gorpMigrationBeforeUpsertHook) - 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) - } - gorpMigrationBeforeUpsertHooks = []GorpMigrationHook{} - - AddGorpMigrationHook(boil.AfterUpsertHook, gorpMigrationAfterUpsertHook) - 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) - } - gorpMigrationAfterUpsertHooks = []GorpMigrationHook{} -} - -func testGorpMigrationsInsert(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 1 { - t.Error("want one record, got:", count) - } -} - -func testGorpMigrationsInsertWhitelist(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = o.Insert(ctx, tx, boil.Whitelist(gorpMigrationColumnsWithoutDefault...)); err != nil { - t.Error(err) - } - - count, err := GorpMigrations().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 1 { - t.Error("want one record, got:", count) - } -} - -func testGorpMigrationsReload(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 testGorpMigrationsReloadAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrationSlice{o} - - if err = slice.ReloadAll(ctx, tx); err != nil { - t.Error(err) - } -} - -func testGorpMigrationsSelect(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().All(ctx, tx) - if err != nil { - t.Error(err) - } - - if len(slice) != 1 { - t.Error("want one record, got:", len(slice)) - } -} - -var ( - gorpMigrationDBTypes = map[string]string{`ID`: `VARCHAR(255)`, `AppliedAt`: `DATETIME`} - _ = bytes.MinRead -) - -func testGorpMigrationsUpdate(t *testing.T) { - t.Parallel() - - if 0 == len(gorpMigrationPrimaryKeyColumns) { - t.Skip("Skipping table with no primary key columns") - } - if len(gorpMigrationAllColumns) == len(gorpMigrationPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().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, gorpMigrationDBTypes, true, gorpMigrationPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 testGorpMigrationsSliceUpdateAll(t *testing.T) { - t.Parallel() - - if len(gorpMigrationAllColumns) == len(gorpMigrationPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - o := &GorpMigration{} - if err = randomize.Struct(seed, o, gorpMigrationDBTypes, true, gorpMigrationColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize GorpMigration 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 := GorpMigrations().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, gorpMigrationDBTypes, true, gorpMigrationPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize GorpMigration struct: %s", err) - } - - // Remove Primary keys and unique columns from what we plan to update - var fields []string - if strmangle.StringSliceMatch(gorpMigrationAllColumns, gorpMigrationPrimaryKeyColumns) { - fields = gorpMigrationAllColumns - } else { - fields = strmangle.SetComplement( - gorpMigrationAllColumns, - gorpMigrationPrimaryKeyColumns, - ) - } - - 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 := GorpMigrationSlice{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) - } -} diff --git a/internal/db/sqlite/models/metadata/headers_test.go b/internal/db/sqlite/models/metadata/headers_test.go deleted file mode 100644 index 75f83cf..0000000 --- a/internal/db/sqlite/models/metadata/headers_test.go +++ /dev/null @@ -1,731 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "bytes" - "context" - "reflect" - "testing" - - "github.com/volatiletech/randomize" - "github.com/volatiletech/sqlboiler/v4/boil" - "github.com/volatiletech/sqlboiler/v4/queries" - "github.com/volatiletech/strmangle" -) - -func testHeadersUpsert(t *testing.T) { - t.Parallel() - if len(headerAllColumns) == len(headerPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - // Attempt the INSERT side of an UPSERT - o := Header{} - if err = randomize.Struct(seed, &o, headerDBTypes, true); err != nil { - t.Errorf("Unable to randomize Header 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 Header: %s", err) - } - - count, err := Headers().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, headerDBTypes, false, headerPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - - if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil { - t.Errorf("Unable to upsert Header: %s", err) - } - - count, err = Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - if count != 1 { - t.Error("want one record, got:", count) - } -} - -var ( - // Relationships sometimes use the reflection helper queries.Equal/queries.Assign - // so force a package dependency in case they don't. - _ = queries.Equal -) - -func testHeaders(t *testing.T) { - t.Parallel() - - query := Headers() - - if query.Query == nil { - t.Error("expected a query, got nothing") - } -} - -func testHeadersDelete(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testHeadersQueryDeleteAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().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 := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testHeadersSliceDeleteAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := HeaderSlice{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 := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 0 { - t.Error("want zero records, got:", count) - } -} - -func testHeadersExists(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := HeaderExists(ctx, tx, o.Name) - if err != nil { - t.Errorf("Unable to check if Header exists: %s", err) - } - if !e { - t.Errorf("Expected HeaderExists to return true, but got false.") - } -} - -func testHeadersFind(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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) - } - - headerFound, err := FindHeader(ctx, tx, o.Name) - if err != nil { - t.Error(err) - } - - if headerFound == nil { - t.Error("want a record, got nil") - } -} - -func testHeadersBind(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 = Headers().Bind(ctx, tx, o); err != nil { - t.Error(err) - } -} - -func testHeadersOne(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().One(ctx, tx); err != nil { - t.Error(err) - } else if x == nil { - t.Error("expected to get a non nil record") - } -} - -func testHeadersAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - headerOne := &Header{} - headerTwo := &Header{} - if err = randomize.Struct(seed, headerOne, headerDBTypes, false, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - if err = randomize.Struct(seed, headerTwo, headerDBTypes, false, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = headerOne.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - if err = headerTwo.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - - slice, err := Headers().All(ctx, tx) - if err != nil { - t.Error(err) - } - - if len(slice) != 2 { - t.Error("want 2 records, got:", len(slice)) - } -} - -func testHeadersCount(t *testing.T) { - t.Parallel() - - var err error - seed := randomize.NewSeed() - headerOne := &Header{} - headerTwo := &Header{} - if err = randomize.Struct(seed, headerOne, headerDBTypes, false, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - if err = randomize.Struct(seed, headerTwo, headerDBTypes, false, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = headerOne.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - if err = headerTwo.Insert(ctx, tx, boil.Infer()); err != nil { - t.Error(err) - } - - count, err := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 2 { - t.Error("want 2 records, got:", count) - } -} - -func headerBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func headerAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Header) error { - *o = Header{} - return nil -} - -func testHeadersHooks(t *testing.T) { - t.Parallel() - - var err error - - ctx := context.Background() - empty := &Header{} - o := &Header{} - - seed := randomize.NewSeed() - if err = randomize.Struct(seed, o, headerDBTypes, false); err != nil { - t.Errorf("Unable to randomize Header object: %s", err) - } - - AddHeaderHook(boil.BeforeInsertHook, headerBeforeInsertHook) - 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) - } - headerBeforeInsertHooks = []HeaderHook{} - - AddHeaderHook(boil.AfterInsertHook, headerAfterInsertHook) - 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) - } - headerAfterInsertHooks = []HeaderHook{} - - AddHeaderHook(boil.AfterSelectHook, headerAfterSelectHook) - 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) - } - headerAfterSelectHooks = []HeaderHook{} - - AddHeaderHook(boil.BeforeUpdateHook, headerBeforeUpdateHook) - 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) - } - headerBeforeUpdateHooks = []HeaderHook{} - - AddHeaderHook(boil.AfterUpdateHook, headerAfterUpdateHook) - 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) - } - headerAfterUpdateHooks = []HeaderHook{} - - AddHeaderHook(boil.BeforeDeleteHook, headerBeforeDeleteHook) - 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) - } - headerBeforeDeleteHooks = []HeaderHook{} - - AddHeaderHook(boil.AfterDeleteHook, headerAfterDeleteHook) - 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) - } - headerAfterDeleteHooks = []HeaderHook{} - - AddHeaderHook(boil.BeforeUpsertHook, headerBeforeUpsertHook) - 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) - } - headerBeforeUpsertHooks = []HeaderHook{} - - AddHeaderHook(boil.AfterUpsertHook, headerAfterUpsertHook) - 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) - } - headerAfterUpsertHooks = []HeaderHook{} -} - -func testHeadersInsert(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 1 { - t.Error("want one record, got:", count) - } -} - -func testHeadersInsertWhitelist(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - - ctx := context.Background() - tx := MustTx(boil.BeginTx(ctx, nil)) - defer func() { _ = tx.Rollback() }() - if err = o.Insert(ctx, tx, boil.Whitelist(headerColumnsWithoutDefault...)); err != nil { - t.Error(err) - } - - count, err := Headers().Count(ctx, tx) - if err != nil { - t.Error(err) - } - - if count != 1 { - t.Error("want one record, got:", count) - } -} - -func testHeadersReload(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 testHeadersReloadAll(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := HeaderSlice{o} - - if err = slice.ReloadAll(ctx, tx); err != nil { - t.Error(err) - } -} - -func testHeadersSelect(t *testing.T) { - t.Parallel() - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().All(ctx, tx) - if err != nil { - t.Error(err) - } - - if len(slice) != 1 { - t.Error("want one record, got:", len(slice)) - } -} - -var ( - headerDBTypes = map[string]string{`Record`: `INTEGER`, `Lastknownrecord`: `INTEGER`, `Block`: `INTEGER`, `Lastknownblock`: `INTEGER`, `Deleted`: `INTEGER`, `Typeflag`: `INTEGER`, `Name`: `TEXT`, `Linkname`: `TEXT`, `Size`: `INTEGER`, `Mode`: `INTEGER`, `UID`: `INTEGER`, `Gid`: `INTEGER`, `Uname`: `TEXT`, `Gname`: `TEXT`, `Modtime`: `DATE`, `Accesstime`: `DATE`, `Changetime`: `DATE`, `Devmajor`: `INTEGER`, `Devminor`: `INTEGER`, `Paxrecords`: `TEXT`, `Format`: `INTEGER`} - _ = bytes.MinRead -) - -func testHeadersUpdate(t *testing.T) { - t.Parallel() - - if 0 == len(headerPrimaryKeyColumns) { - t.Skip("Skipping table with no primary key columns") - } - if len(headerAllColumns) == len(headerPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().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, headerDBTypes, true, headerPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize Header 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 testHeadersSliceUpdateAll(t *testing.T) { - t.Parallel() - - if len(headerAllColumns) == len(headerPrimaryKeyColumns) { - t.Skip("Skipping table with only primary key columns") - } - - seed := randomize.NewSeed() - var err error - o := &Header{} - if err = randomize.Struct(seed, o, headerDBTypes, true, headerColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize Header 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 := Headers().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, headerDBTypes, true, headerPrimaryKeyColumns...); err != nil { - t.Errorf("Unable to randomize Header struct: %s", err) - } - - // Remove Primary keys and unique columns from what we plan to update - var fields []string - if strmangle.StringSliceMatch(headerAllColumns, headerPrimaryKeyColumns) { - fields = headerAllColumns - } else { - fields = strmangle.SetComplement( - headerAllColumns, - headerPrimaryKeyColumns, - ) - } - - 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 := HeaderSlice{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) - } -} diff --git a/internal/db/sqlite/models/metadata/sqlite3_main_test.go b/internal/db/sqlite/models/metadata/sqlite3_main_test.go deleted file mode 100644 index 13ac3c6..0000000 --- a/internal/db/sqlite/models/metadata/sqlite3_main_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "database/sql" - "fmt" - "io" - "math/rand" - "os" - "os/exec" - "path/filepath" - "regexp" - - "github.com/pkg/errors" - "github.com/spf13/viper" - _ "modernc.org/sqlite" -) - -var rgxSQLitekey = regexp.MustCompile(`(?mi)((,\n)?\s+foreign key.*?\n)+`) - -type sqliteTester struct { - dbConn *sql.DB - - dbName string - testDBName string -} - -func init() { - dbMain = &sqliteTester{} -} - -func (s *sqliteTester) setup() error { - var err error - - s.dbName = viper.GetString("sqlite3.dbname") - if len(s.dbName) == 0 { - return errors.New("no dbname specified") - } - - s.testDBName = filepath.Join(os.TempDir(), fmt.Sprintf("boil-sqlite3-%d.sql", rand.Int())) - - dumpCmd := exec.Command("sqlite3", "-cmd", ".dump", s.dbName) - createCmd := exec.Command("sqlite3", s.testDBName) - - r, w := io.Pipe() - dumpCmd.Stdout = w - createCmd.Stdin = newFKeyDestroyer(rgxSQLitekey, r) - - if err = dumpCmd.Start(); err != nil { - return errors.Wrap(err, "failed to start sqlite3 dump command") - } - if err = createCmd.Start(); err != nil { - return errors.Wrap(err, "failed to start sqlite3 create command") - } - - if err = dumpCmd.Wait(); err != nil { - fmt.Println(err) - return errors.Wrap(err, "failed to wait for sqlite3 dump command") - } - - w.Close() // After dumpCmd is done, close the write end of the pipe - - if err = createCmd.Wait(); err != nil { - fmt.Println(err) - return errors.Wrap(err, "failed to wait for sqlite3 create command") - } - - return nil -} - -func (s *sqliteTester) teardown() error { - if s.dbConn != nil { - s.dbConn.Close() - } - - return os.Remove(s.testDBName) -} - -func (s *sqliteTester) conn() (*sql.DB, error) { - if s.dbConn != nil { - return s.dbConn, nil - } - - var err error - s.dbConn, err = sql.Open("sqlite3", fmt.Sprintf("file:%s?_loc=UTC", s.testDBName)) - if err != nil { - return nil, err - } - - return s.dbConn, nil -} diff --git a/internal/db/sqlite/models/metadata/sqlite3_suites_test.go b/internal/db/sqlite/models/metadata/sqlite3_suites_test.go deleted file mode 100644 index 609aac1..0000000 --- a/internal/db/sqlite/models/metadata/sqlite3_suites_test.go +++ /dev/null @@ -1,12 +0,0 @@ -// Code generated by SQLBoiler 4.8.3 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import "testing" - -func TestUpsert(t *testing.T) { - t.Run("GorpMigrations", testGorpMigrationsUpsert) - - t.Run("Headers", testHeadersUpsert) -}