From 9719d4b0e3bc1104a54a4c683568166bf3aebf29 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 17 Jul 2025 01:11:16 +0100 Subject: [PATCH] Better tests. --- ext/blobio/blob_test.go | 18 ++++---- ext/csv/csv_test.go | 25 +++++----- ext/pivot/pivot_test.go | 8 ++-- ext/statement/stmt_test.go | 4 +- ext/stats/boolean_test.go | 4 +- ext/stats/mode_test.go | 49 ++++++++++---------- ext/stats/percentile_test.go | 52 ++++++++++++--------- ext/stats/stats_test.go | 24 ++++++---- ext/unicode/unicode_test.go | 7 ++- tests/endian_test.go | 8 ++-- tests/func_test.go | 44 +++++++++++++----- tests/stmt_test.go | 60 ++++++++++++++++++------ tests/time_test.go | 4 +- tests/txn_test.go | 90 +++++++++++++----------------------- 14 files changed, 220 insertions(+), 177 deletions(-) diff --git a/ext/blobio/blob_test.go b/ext/blobio/blob_test.go index 03eacbe..f8867d0 100644 --- a/ext/blobio/blob_test.go +++ b/ext/blobio/blob_test.go @@ -144,18 +144,16 @@ func Test_readblob(t *testing.T) { } } - if stmt.Step() { - got := stmt.ColumnText(0) - if got != tt.want1 { - t.Errorf("got %q", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != tt.want1 { + t.Errorf("got %q", got) } - if stmt.Step() { - got := stmt.ColumnText(0) - if got != tt.want2 { - t.Errorf("got %q", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != tt.want2 { + t.Errorf("got %q", got) } err = stmt.Err() diff --git a/ext/csv/csv_test.go b/ext/csv/csv_test.go index 15c8fc2..f748917 100644 --- a/ext/csv/csv_test.go +++ b/ext/csv/csv_test.go @@ -147,20 +147,21 @@ func TestAffinity(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - if got := stmt.ColumnText(0); got != "1" { - t.Errorf("got %q want 1", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != "1" { + t.Errorf("got %q want 1", got) } - if stmt.Step() { - if got := stmt.ColumnText(0); got != "0.1" { - t.Errorf("got %q want 0.1", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != "0.1" { + t.Errorf("got %q want 0.1", got) } - if stmt.Step() { - if got := stmt.ColumnText(0); got != "e" { - t.Errorf("got %q want e", got) - } + + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != "e" { + t.Errorf("got %q want e", got) } } diff --git a/ext/pivot/pivot_test.go b/ext/pivot/pivot_test.go index 1e4a84f..8461d31 100644 --- a/ext/pivot/pivot_test.go +++ b/ext/pivot/pivot_test.go @@ -141,10 +141,10 @@ func TestRegister(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - if got := stmt.ColumnInt(0); got != 3 { - t.Errorf("got %d, want 3", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 3 { + t.Errorf("got %d, want 3", got) } err = db.Exec(`ALTER TABLE v_x RENAME TO v_y`) diff --git a/ext/statement/stmt_test.go b/ext/statement/stmt_test.go index 48a1d98..fb63dcc 100644 --- a/ext/statement/stmt_test.go +++ b/ext/statement/stmt_test.go @@ -92,7 +92,9 @@ func TestRegister(t *testing.T) { } defer stmt.Close() - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { x := stmt.ColumnInt(0) y := stmt.ColumnInt(1) hypot := stmt.ColumnInt(2) diff --git a/ext/stats/boolean_test.go b/ext/stats/boolean_test.go index 7ea2536..60f6579 100644 --- a/ext/stats/boolean_test.go +++ b/ext/stats/boolean_test.go @@ -37,7 +37,9 @@ func TestRegister_boolean(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnBool(0); got != true { t.Errorf("got %v, want true", got) } diff --git a/ext/stats/mode_test.go b/ext/stats/mode_test.go index 63a440a..31e446a 100644 --- a/ext/stats/mode_test.go +++ b/ext/stats/mode_test.go @@ -21,10 +21,10 @@ func TestRegister_mode(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnInt(0); got != 3 { - t.Errorf("got %v, want 3", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 3 { + t.Errorf("got %v, want 3", got) } stmt.Close() @@ -32,10 +32,10 @@ func TestRegister_mode(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnInt(0); got != 1 { - t.Errorf("got %v, want 1", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %v, want 1", got) } stmt.Close() @@ -43,10 +43,10 @@ func TestRegister_mode(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 2.5 { - t.Errorf("got %v, want 2.5", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 2.5 { + t.Errorf("got %v, want 2.5", got) } stmt.Close() @@ -54,21 +54,22 @@ func TestRegister_mode(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnText(0); got != "red" { - t.Errorf("got %q, want red", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != "red" { + t.Errorf("got %q, want red", got) } + stmt.Close() stmt, _, err = db.Prepare(`SELECT mode(column1) FROM (VALUES (X'cafebabe'), ('green'), ('blue'), (X'cafebabe'))`) if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnText(0); got != "\xca\xfe\xba\xbe" { - t.Errorf("got %q, want cafebabe", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnText(0); got != "\xca\xfe\xba\xbe" { + t.Errorf("got %q, want cafebabe", got) } stmt.Close() @@ -92,10 +93,10 @@ func TestRegister_mode(t *testing.T) { stmt.BindInt(3, 2) stmt.BindFloat(4, 2) stmt.BindFloat(5, 2) - if stmt.Step() { - if got := stmt.ColumnInt(0); got != 2 { - t.Errorf("got %v, want 2", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 2 { + t.Errorf("got %v, want 2", got) } stmt.Close() } diff --git a/ext/stats/percentile_test.go b/ext/stats/percentile_test.go index 985f10e..4d612d4 100644 --- a/ext/stats/percentile_test.go +++ b/ext/stats/percentile_test.go @@ -38,7 +38,9 @@ func TestRegister_percentile(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnFloat(0); got != 10 { t.Errorf("got %v, want 10", got) } @@ -65,30 +67,30 @@ func TestRegister_percentile(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 5.5 { - t.Errorf("got %v, want 5.5", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 5.5 { + t.Errorf("got %v, want 5.5", got) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 7 { - t.Errorf("got %v, want 7", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 7 { + t.Errorf("got %v, want 7", got) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 10 { - t.Errorf("got %v, want 10", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 10 { + t.Errorf("got %v, want 10", got) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 14.5 { - t.Errorf("got %v, want 14.5", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 14.5 { + t.Errorf("got %v, want 14.5", got) } - if stmt.Step() { - if got := stmt.ColumnFloat(0); got != 16 { - t.Errorf("got %v, want 16", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnFloat(0); got != 16 { + t.Errorf("got %v, want 16", got) } stmt.Close() @@ -103,7 +105,9 @@ func TestRegister_percentile(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnFloat(0); got != 4 { t.Errorf("got %v, want 4", got) } @@ -134,7 +138,9 @@ func TestRegister_percentile(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.NULL { t.Error("want NULL") } diff --git a/ext/stats/stats_test.go b/ext/stats/stats_test.go index 7c14638..7e5b081 100644 --- a/ext/stats/stats_test.go +++ b/ext/stats/stats_test.go @@ -34,10 +34,10 @@ func TestRegister_variance(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { - if got := stmt.ColumnType(0); got != sqlite3.NULL { - t.Errorf("got %v, want NULL", got) - } + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnType(0); got != sqlite3.NULL { + t.Errorf("got %v, want NULL", got) } stmt.Close() @@ -57,7 +57,9 @@ func TestRegister_variance(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnFloat(0); got != 40 { t.Errorf("got %v, want 40", got) } @@ -131,7 +133,9 @@ func TestRegister_covariance(t *testing.T) { if err != nil { t.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnInt(0); got != 0 { t.Errorf("got %v, want 0", got) } @@ -249,7 +253,9 @@ func Benchmark_average(b *testing.B) { b.Fatal(err) } - if stmt.Step() { + if !stmt.Step() { + b.Fatal(stmt.Err()) + } else { want := float64(b.N) / 2 if got := stmt.ColumnFloat(0); got != want { b.Errorf("got %v, want %v", got, want) @@ -283,7 +289,9 @@ func Benchmark_variance(b *testing.B) { b.Fatal(err) } - if stmt.Step() && b.N > 100 { + if !stmt.Step() { + b.Fatal(stmt.Err()) + } else if b.N > 100 { want := float64(b.N*b.N) / 12 if got := stmt.ColumnFloat(0); want > (got-want)*float64(b.N) { b.Errorf("got %v, want %v", got, want) diff --git a/ext/unicode/unicode_test.go b/ext/unicode/unicode_test.go index c5bd4d8..86a28fd 100644 --- a/ext/unicode/unicode_test.go +++ b/ext/unicode/unicode_test.go @@ -26,11 +26,10 @@ func TestRegister(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - return stmt.ColumnText(0) + if !stmt.Step() { + t.Fatal(stmt.Err()) } - t.Fatal(stmt.Err()) - return "" + return stmt.ColumnText(0) } Register(db) diff --git a/tests/endian_test.go b/tests/endian_test.go index 335567d..36e7a9c 100644 --- a/tests/endian_test.go +++ b/tests/endian_test.go @@ -59,7 +59,9 @@ func Test_endianness(t *testing.T) { } defer stmt.Close() - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnInt64(0); got != value { t.Errorf("got %d, want %d", got, value) } @@ -67,9 +69,5 @@ func Test_endianness(t *testing.T) { t.Errorf("got %s, want %d", got, value) } } - if err != nil { - t.Fatal(err) - } } - } diff --git a/tests/func_test.go b/tests/func_test.go index 0a74d9e..e34bc03 100644 --- a/tests/func_test.go +++ b/tests/func_test.go @@ -64,7 +64,9 @@ func TestCreateFunction(t *testing.T) { } defer stmt.Close() - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -73,7 +75,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -82,7 +86,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -91,7 +97,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.FLOAT { t.Errorf("got %v, want FLOAT", got) } @@ -100,7 +108,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -109,7 +119,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.BLOB { t.Errorf("got %v, want BLOB", got) } @@ -118,7 +130,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.BLOB { t.Errorf("got %v, want BLOB", got) } @@ -127,7 +141,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -136,7 +152,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -148,7 +166,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -157,7 +177,9 @@ func TestCreateFunction(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.NULL { t.Errorf("got %v, want NULL", got) } diff --git a/tests/stmt_test.go b/tests/stmt_test.go index 2ef0bee..92aa920 100644 --- a/tests/stmt_test.go +++ b/tests/stmt_test.go @@ -168,7 +168,9 @@ func TestStmt(t *testing.T) { t.Errorf(`got %q, want "main"`, got) } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -195,7 +197,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -222,7 +226,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.INTEGER { t.Errorf("got %v, want INTEGER", got) } @@ -249,7 +255,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.FLOAT { t.Errorf("got %v, want FLOAT", got) } @@ -276,7 +284,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.NULL { t.Errorf("got %v, want NULL", got) } @@ -303,7 +313,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -328,7 +340,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -353,7 +367,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -378,7 +394,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.BLOB { t.Errorf("got %v, want BLOB", got) } @@ -403,7 +421,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.BLOB { t.Errorf("got %v, want BLOB", got) } @@ -428,7 +448,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.BLOB { t.Errorf("got %v, want BLOB", got) } @@ -453,7 +475,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.TEXT { t.Errorf("got %v, want TEXT", got) } @@ -480,7 +504,9 @@ func TestStmt(t *testing.T) { } } - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { if got := stmt.ColumnType(0); got != sqlite3.NULL { t.Errorf("got %v, want NULL", got) } @@ -643,7 +669,9 @@ func TestStmt_ColumnValue(t *testing.T) { } defer stmt.Close() - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { val := stmt.ColumnValue(0) if _, err := val.InFirst(); err == nil { t.Error("want error") @@ -675,7 +703,9 @@ func TestStmt_Columns(t *testing.T) { } defer stmt.Close() - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { var dest [5]any if err := stmt.Columns(dest[:]...); err != nil { t.Fatal(err) diff --git a/tests/time_test.go b/tests/time_test.go index d268315..dd3c342 100644 --- a/tests/time_test.go +++ b/tests/time_test.go @@ -244,7 +244,9 @@ func TestDB_isoWeek(t *testing.T) { tstart := time.Date(1500, 1, 1, 12, 0, 0, 0, time.UTC) for tm := tstart; tm.Before(tend); tm = tm.AddDate(0, 0, 1) { stmt.BindTime(1, tm, sqlite3.TimeFormatDefault) - if stmt.Step() { + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else { y, w := tm.ISOWeek() d := tm.Weekday() if d == 0 { diff --git a/tests/txn_test.go b/tests/txn_test.go index c1f15fe..ba52c23 100644 --- a/tests/txn_test.go +++ b/tests/txn_test.go @@ -37,11 +37,10 @@ func TestConn_Transaction_exec(t *testing.T) { t.Fatal(err) } defer stmt.Close() - if stmt.Step() { - return stmt.ColumnInt(0) + if !stmt.Step() { + t.Fatal(stmt.Err()) } - t.Fatal(stmt.Err()) - return 0 + return stmt.ColumnInt(0) } insert := func(succeed bool) (err error) { @@ -130,14 +129,12 @@ func TestConn_Transaction_panic(t *testing.T) { t.Fatal(err) } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - return + if !stmt.Step() { + t.Fatal(stmt.Err()) + } + if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } - t.Fatal(stmt.Err()) }() err = panics() @@ -213,15 +210,10 @@ func TestConn_Transaction_interrupt(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - } - err = stmt.Err() - if err != nil { - t.Error(err) + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } } @@ -333,15 +325,10 @@ func TestConn_Transaction_rollback(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - } - err = stmt.Err() - if err != nil { - t.Error(err) + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } } @@ -382,11 +369,10 @@ func TestConn_Savepoint_exec(t *testing.T) { t.Fatal(err) } defer stmt.Close() - if stmt.Step() { - return stmt.ColumnInt(0) + if !stmt.Step() { + t.Fatal(stmt.Err()) } - t.Fatal(stmt.Err()) - return 0 + return stmt.ColumnInt(0) } insert := func(succeed bool) (err error) { @@ -469,14 +455,12 @@ func TestConn_Savepoint_panic(t *testing.T) { t.Fatal(err) } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - return + if !stmt.Step() { + t.Fatal(stmt.Err()) + } + if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } - t.Fatal(stmt.Err()) }() err = panics() @@ -553,15 +537,10 @@ func TestConn_Savepoint_interrupt(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - } - err = stmt.Err() - if err != nil { - t.Error(err) + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } } @@ -599,14 +578,9 @@ func TestConn_Savepoint_rollback(t *testing.T) { } defer stmt.Close() - if stmt.Step() { - got := stmt.ColumnInt(0) - if got != 1 { - t.Errorf("got %d, want 1", got) - } - } - err = stmt.Err() - if err != nil { - t.Error(err) + if !stmt.Step() { + t.Fatal(stmt.Err()) + } else if got := stmt.ColumnInt(0); got != 1 { + t.Errorf("got %d, want 1", got) } }