-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/grafana/xk6-sql/sqltest" | ||
) | ||
|
||
//go:embed testdata/script.js | ||
var script string | ||
|
||
func TestIntegration(t *testing.T) { //nolint:paralleltest | ||
sqltest.RunScript(t, "sqlite3", "integration-test.db", script) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const db = sql.open(driver, connection); | ||
|
||
db.exec( | ||
"CREATE TABLE IF NOT EXISTS test_table (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, value VARCHAR(50));DELETE FROM test_table;" | ||
); | ||
|
||
for (let i = 0; i < 5; i++) { | ||
db.exec("INSERT INTO test_table (name, value) VALUES ('name-" + i + "', 'value-" + i + "');"); | ||
} | ||
|
||
let all_rows = sql.query(db, "SELECT * FROM test_table;"); | ||
if (all_rows.length != 5) { | ||
throw new Error("Expected all five rows to be returned; got " + all_rows.length); | ||
} | ||
|
||
let one_row = sql.query(db, "SELECT * FROM test_table WHERE name = $1;", "name-2"); | ||
if (one_row.length != 1) { | ||
throw new Error("Expected single row to be returned; got " + one_row.length); | ||
} | ||
|
||
let no_rows = sql.query(db, "SELECT * FROM test_table WHERE name = $1;", "bogus-name"); | ||
if (no_rows.length != 0) { | ||
throw new Error("Expected no rows to be returned; got " + no_rows.length); | ||
} | ||
|
||
db.close(); |