-
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.
Merge pull request #80 from grafana/75-create-driver-packages
create driver packages
- Loading branch information
Showing
27 changed files
with
555 additions
and
127 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,12 @@ | ||
// Package azuresql contains azuresql SQL driver registration for xk6-sql. | ||
package azuresql | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
"github.com/microsoft/go-mssqldb/azuread" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule(azuread.DriverName) | ||
} |
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,13 @@ | ||
// Package clickhouse contains ClickHouse SQL driver registration for xk6-sql. | ||
package clickhouse | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
// Blank imports required for initialization of driver. | ||
_ "github.com/ClickHouse/clickhouse-go/v2" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule("clickhouse") | ||
} |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
// Package mysql contains MySQL driver registration for xk6-sql. | ||
package mysql | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
// Blank import required for initialization of driver. | ||
_ "github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule("mysql") | ||
} |
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,39 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/grafana/xk6-sql/sqltest" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/testcontainers/testcontainers-go/modules/mysql" | ||
) | ||
|
||
//go:embed testdata/script.js | ||
var script string | ||
|
||
func TestIntegration(t *testing.T) { //nolint:paralleltest | ||
if testing.Short() { | ||
t.Skip() | ||
} | ||
|
||
if runtime.GOOS != "linux" { | ||
t.Skip("Works only on Linux (Testcontainers)") | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
ctr, err := mysql.Run(ctx, "mysql:8.0.36") | ||
|
||
require.NoError(t, err) | ||
defer func() { require.NoError(t, ctr.Terminate(ctx)) }() | ||
|
||
conn, err := ctr.ConnectionString(ctx) | ||
|
||
require.NoError(t, err) | ||
|
||
sqltest.RunScript(t, "mysql", conn, 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 test_table (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, value VARCHAR(50));" | ||
); | ||
|
||
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 = ?;", "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 = ?;", "bogus-name"); | ||
if (no_rows.length != 0) { | ||
throw new Error("Expected no rows to be returned; got " + no_rows.length); | ||
} | ||
|
||
db.close(); |
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,13 @@ | ||
// Package postgres contains PostgreSQL SQL driver registration for xk6-sql. | ||
package postgres | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
// Blank import required for initialization of driver. | ||
_ "github.com/lib/pq" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule("postgres") | ||
} |
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,45 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/grafana/xk6-sql/sqltest" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/modules/postgres" | ||
"github.com/testcontainers/testcontainers-go/wait" | ||
) | ||
|
||
//go:embed testdata/script.js | ||
var script string | ||
|
||
func TestIntegration(t *testing.T) { //nolint:paralleltest | ||
if testing.Short() { | ||
t.Skip() | ||
} | ||
|
||
if runtime.GOOS != "linux" { | ||
t.Skip("Works only on Linux (Testcontainers)") | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
ctr, err := postgres.Run(ctx, "docker.io/postgres:16-alpine", | ||
testcontainers.WithWaitStrategy( | ||
wait.ForLog("database system is ready to accept connections"). | ||
WithOccurrence(2)), | ||
) | ||
|
||
require.NoError(t, err) | ||
defer func() { require.NoError(t, ctr.Terminate(ctx)) }() | ||
|
||
conn, err := ctr.ConnectionString(ctx, "sslmode=disable") | ||
|
||
require.NoError(t, err) | ||
|
||
sqltest.RunScript(t, "postgres", conn, 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,24 @@ | ||
const db = sql.open(driver, connection); | ||
|
||
db.exec("CREATE TABLE test_table (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, value VARCHAR(50));"); | ||
|
||
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(); |
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,13 @@ | ||
// Package sqlite3 contains SQLite3 driver registration for xk6-sql. | ||
package sqlite3 | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
// Blank import required for initialization of driver. | ||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule("sqlite3") | ||
} |
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(); |
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,13 @@ | ||
// Package sqlserver contains Miscrosoft SQL server driver registration for xk6-sql. | ||
package sqlserver | ||
|
||
import ( | ||
"github.com/grafana/xk6-sql/sql" | ||
|
||
// Blank import required for initialization of driver. | ||
_ "github.com/microsoft/go-mssqldb" | ||
) | ||
|
||
func init() { | ||
sql.RegisterModule("sqlserver") | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import sql from 'k6/x/sql'; | ||
import driver from "k6/x/sql/driver/postgres"; | ||
|
||
// The second argument is a PostgreSQL connection string, e.g. | ||
// postgres://myuser:[email protected]:5432/postgres?sslmode=disable | ||
const db = sql.open('postgres', ''); | ||
const db = sql.open(driver, ''); | ||
|
||
export function setup() { | ||
db.exec(`CREATE TABLE IF NOT EXISTS keyvalues ( | ||
|
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
Oops, something went wrong.