Skip to content

Commit

Permalink
test: added integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Oct 17, 2024
1 parent 01fb2be commit e7561da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/sqlite3/register_test.go
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)
}
26 changes: 26 additions & 0 deletions drivers/sqlite3/testdata/script.js
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();

0 comments on commit e7561da

Please sign in to comment.