Skip to content

Commit

Permalink
Add tests for db.Exec and INSERT
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Oct 19, 2023
1 parent 0fcb544 commit 96d3bf4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions trino/etc/catalog/memory.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connector.name=memory
49 changes: 49 additions & 0 deletions trino/trino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,3 +1719,52 @@ func BenchmarkQuery(b *testing.B) {
rows.Close()
}
}

func TestExec(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
c := &Config{
ServerURI: *integrationServerFlag,
SessionProperties: map[string]string{"query_priority": "1"},
}

dsn, err := c.FormatDSN()
require.NoError(t, err)

db, err := sql.Open("trino", dsn)
require.NoError(t, err)

t.Cleanup(func() {
assert.NoError(t, db.Close())
})

result, err := db.Exec("CREATE TABLE memory.default.test (id INTEGER, name VARCHAR)")
require.NoError(t, err, "Failed executing CREATE TABLE query")

result, err = db.Exec("INSERT INTO memory.default.test (id, name) VALUES (?, ?), (?, ?), (?, ?)", 123, "abc", 456, "def", 789, "ghi")
require.NoError(t, err, "Failed executing INSERT query")
_, err = result.LastInsertId()
assert.Error(t, err, "trino: operation not supported")
numRows, err := result.RowsAffected()
require.NoError(t, err, "Failed checking rows affected")
assert.Equal(t, numRows, int64(3))

rows, err := db.Query("SELECT * FROM memory.default.test")
require.NoError(t, err, "Failed executing DELETE query")

expectedIds := []int{123, 456, 789}
expectedNames := []string{"abc", "def", "ghi"}
actualIds := []int{}
actualNames := []string{}
for rows.Next() {
var id int
var name string
require.NoError(t, rows.Scan(&id, &name), "Failed scanning query result")
actualIds = append(actualIds, id)
actualNames = append(actualNames, name)

}
assert.Equal(t, expectedIds, actualIds)
assert.Equal(t, expectedNames, actualNames)
}

0 comments on commit 96d3bf4

Please sign in to comment.