Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-859548 Replace test table in each test #858

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestBindingFloat64(t *testing.T) {
var out float64
var rows *RowsExtended
for _, v := range types {
dbt.mustExec(fmt.Sprintf("CREATE TABLE test (id int, value %v)", v))
dbt.mustExec(fmt.Sprintf("CREATE OR REPLACE TABLE test (id int, value %v)", v))
sfc-gh-igarish marked this conversation as resolved.
Show resolved Hide resolved
dbt.mustExec("INSERT INTO test VALUES (1, ?)", expected)
rows = dbt.mustQuery("SELECT value FROM test WHERE id = ?", 1)
defer rows.Close()
Expand All @@ -67,7 +67,7 @@ func TestBindingUint64(t *testing.T) {
types := []string{"INTEGER"}
expected := uint64(18446744073709551615)
for _, v := range types {
dbt.mustExec(fmt.Sprintf("CREATE TABLE test (id int, value %v)", v))
dbt.mustExec(fmt.Sprintf("CREATE OR REPLACE TABLE test (id int, value %v)", v))
if _, err := dbt.exec("INSERT INTO test VALUES (1, ?)", expected); err == nil {
dbt.Fatal("should fail as uint64 values with high bit set are not supported.")
} else {
Expand Down
20 changes: 7 additions & 13 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,12 @@ func (dbt *DBTest) mustPrepare(query string) (stmt *sql.Stmt) {
}

func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
ctx := context.Background()
conn := openConn(t)
dbt := &DBTest{t, conn}
defer conn.Close()

if _, err := conn.ExecContext(ctx, "DROP TABLE IF EXISTS test"); err != nil {
t.Fatalf("failed to drop table: %v", err)
}

for _, test := range tests {
test(dbt)
dbt.conn.ExecContext(ctx, "DROP TABLE IF EXISTS test")
}
}

Expand Down Expand Up @@ -466,7 +460,7 @@ func TestEmptyQueryWithRequestID(t *testing.T) {
func TestCRUD(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
// Create Table
dbt.mustExec("CREATE TABLE test (value BOOLEAN)")
dbt.mustExec("CREATE OR REPLACE TABLE test (value BOOLEAN)")

// Test for unexpected Data
var out bool
Expand Down Expand Up @@ -573,7 +567,7 @@ func testInt(t *testing.T, json bool) {
if json {
dbt.mustExec(forceJSON)
}
dbt.mustExec("CREATE TABLE test (value " + v + ")")
dbt.mustExec("CREATE OR REPLACE TABLE test (value " + v + ")")
dbt.mustExec("INSERT INTO test VALUES (?)", in)
rows = dbt.mustQuery("SELECT value FROM test")
defer rows.Close()
Expand Down Expand Up @@ -605,7 +599,7 @@ func testFloat32(t *testing.T, json bool) {
if json {
dbt.mustExec(forceJSON)
}
dbt.mustExec("CREATE TABLE test (value " + v + ")")
dbt.mustExec("CREATE OR REPLACE TABLE test (value " + v + ")")
dbt.mustExec("INSERT INTO test VALUES (?)", in)
rows = dbt.mustQuery("SELECT value FROM test")
defer rows.Close()
Expand Down Expand Up @@ -639,7 +633,7 @@ func testFloat64(t *testing.T, json bool) {
if json {
dbt.mustExec(forceJSON)
}
dbt.mustExec("CREATE TABLE test (value " + v + ")")
dbt.mustExec("CREATE OR REPLACE TABLE test (value " + v + ")")
dbt.mustExec("INSERT INTO test VALUES (42.23)")
rows = dbt.mustQuery("SELECT value FROM test")
defer rows.Close()
Expand Down Expand Up @@ -671,7 +665,7 @@ func testString(t *testing.T, json bool) {
var rows *RowsExtended

for _, v := range types {
dbt.mustExec("CREATE TABLE test (value " + v + ")")
dbt.mustExec("CREATE OR REPLACE TABLE test (value " + v + ")")
dbt.mustExec("INSERT INTO test VALUES (?)", in)

rows = dbt.mustQuery("SELECT value FROM test")
Expand All @@ -688,7 +682,7 @@ func testString(t *testing.T, json bool) {
}

// BLOB (Snowflake doesn't support BLOB type but STRING covers large text data)
dbt.mustExec("CREATE TABLE test (id int, value STRING)")
dbt.mustExec("CREATE OR REPLACE TABLE test (id int, value STRING)")

id := 2
in = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
Expand Down Expand Up @@ -1133,7 +1127,7 @@ func testNULL(t *testing.T, json bool) {
}

// Insert NULL
dbt.mustExec("CREATE TABLE test (dummmy1 int, value int, dummy2 int)")
dbt.mustExec("CREATE OR REPLACE TABLE test (dummmy1 int, value int, dummy2 int)")
dbt.mustExec("INSERT INTO test VALUES (?, ?, ?)", 1, nil, 2)

var out interface{}
Expand Down