From c31b1f30ed8f16fc5974d29e764cc96b99f89f27 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Thu, 11 Jul 2024 15:09:25 +0800 Subject: [PATCH] rm redundant function --- indexer/test_helpers/test_helpers.go | 19 +++++++++------- test_helpers/db.go | 34 ---------------------------- 2 files changed, 11 insertions(+), 42 deletions(-) delete mode 100644 test_helpers/db.go diff --git a/indexer/test_helpers/test_helpers.go b/indexer/test_helpers/test_helpers.go index 7e65154..d8b1ec2 100644 --- a/indexer/test_helpers/test_helpers.go +++ b/indexer/test_helpers/test_helpers.go @@ -19,6 +19,7 @@ package test_helpers import ( "bufio" "context" + "fmt" "os" "testing" @@ -39,9 +40,6 @@ func DedupFile(filePath string) error { s := sc.Text() stmts[s] = struct{}{} } - if err != nil { - return err - } f.Close() @@ -60,10 +58,17 @@ func DedupFile(filePath string) error { // TearDownDB is used to tear down the watcher dbs after tests func TearDownDB(t *testing.T, db sql.Database) { + err := ClearDB(db) + if err != nil { + t.Fatal(err) + } +} + +func ClearDB(db sql.Database) error { ctx := context.Background() tx, err := db.Begin(ctx) if err != nil { - t.Fatal(err) + return err } statements := []string{ @@ -81,10 +86,8 @@ func TearDownDB(t *testing.T, db sql.Database) { } for _, stm := range statements { if _, err = tx.Exec(ctx, stm); err != nil { - t.Fatal(err) + return fmt.Errorf("error executing `%s`: %w", stm, err) } } - if err = tx.Commit(ctx); err != nil { - t.Fatal(err) - } + return tx.Commit(ctx) } diff --git a/test_helpers/db.go b/test_helpers/db.go deleted file mode 100644 index 34f5462..0000000 --- a/test_helpers/db.go +++ /dev/null @@ -1,34 +0,0 @@ -package test_helpers - -import ( - "fmt" - - "github.com/jmoiron/sqlx" -) - -// ClearDB is used to empty the IPLD-ETH tables after tests -func ClearDB(db *sqlx.DB) error { - tx, err := db.Beginx() - if err != nil { - return err - } - statements := []string{ - `TRUNCATE nodes`, - `TRUNCATE ipld.blocks`, - `TRUNCATE eth.header_cids`, - `TRUNCATE eth.uncle_cids`, - `TRUNCATE eth.transaction_cids`, - `TRUNCATE eth.receipt_cids`, - `TRUNCATE eth.state_cids`, - `TRUNCATE eth.storage_cids`, - `TRUNCATE eth.log_cids`, - `TRUNCATE eth.withdrawal_cids`, - `TRUNCATE eth_meta.watched_addresses`, - } - for _, stm := range statements { - if _, err = tx.Exec(stm); err != nil { - return fmt.Errorf("error executing `%s`: %w", stm, err) - } - } - return tx.Commit() -}