From a4843594b8c8b87ba4ac17842a66239960058180 Mon Sep 17 00:00:00 2001 From: Jan Was Date: Fri, 8 Jul 2022 18:29:09 +0200 Subject: [PATCH] Test for specific errors --- trino/integration_test.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/trino/integration_test.go b/trino/integration_test.go index 329179a..b538d2f 100644 --- a/trino/integration_test.go +++ b/trino/integration_test.go @@ -111,14 +111,14 @@ func TestIntegrationSelectQueryIterator(t *testing.T) { t.Fatal(err) } if col.NodeID != "test" { - t.Fatal("node_id != test") + t.Errorf("Expected node_id == test but got %s", col.NodeID) } } if err = rows.Err(); err != nil { t.Fatal(err) } if count < 1 { - t.Fatal("no rows returned") + t.Error("no rows returned") } } @@ -361,7 +361,7 @@ func TestIntegrationQueryParametersSelect(t *testing.T) { name string query string args []interface{} - expectedError bool + expectedError error expectedRows int }{ { @@ -380,13 +380,13 @@ func TestIntegrationQueryParametersSelect(t *testing.T) { name: "invalid string as bigint", query: "SELECT * FROM tpch.sf1.customer WHERE custkey=? LIMIT 2", args: []interface{}{"1"}, - expectedError: true, + expectedError: errors.New(`trino: query failed (200 OK): "io.trino.spi.TrinoException: line 1:46: Cannot apply operator: bigint = varchar(1)"`), }, { name: "valid string as date", query: "SELECT * FROM tpch.sf1.lineitem WHERE shipdate=? LIMIT 2", args: []interface{}{"1995-01-27"}, - expectedError: true, + expectedError: errors.New(`trino: query failed (200 OK): "io.trino.spi.TrinoException: line 1:47: Cannot apply operator: date = varchar(10)"`), }, } @@ -399,17 +399,23 @@ func TestIntegrationQueryParametersSelect(t *testing.T) { rows, err := db.Query(scenario.query, scenario.args...) if err != nil { - if scenario.expectedError { + if scenario.expectedError == nil { + t.Errorf("Unexpected err: %s", err) return } - t.Fatal(err) + if err.Error() == scenario.expectedError.Error() { + return + } + t.Errorf("Expected err to be %s but got %s", scenario.expectedError, err) } - defer rows.Close() - if scenario.expectedError { - t.Fatal("missing expected error") + if scenario.expectedError != nil { + t.Error("missing expected error") + return } + defer rows.Close() + var count int for rows.Next() { count++ @@ -418,7 +424,7 @@ func TestIntegrationQueryParametersSelect(t *testing.T) { t.Fatal(err) } if count != scenario.expectedRows { - t.Fatalf("expecting %d rows, got %d", scenario.expectedRows, count) + t.Errorf("expecting %d rows, got %d", scenario.expectedRows, count) } }) }