-
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 #93 from grafana/92-api-refactoring-query-function
API refactoring: move query function to Database interface
- Loading branch information
Showing
11 changed files
with
145 additions
and
43 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: CI | ||
name: Test | ||
|
||
on: | ||
workflow_dispatch: | ||
|
@@ -10,7 +10,7 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
build: | ||
coverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
|
@@ -19,7 +19,7 @@ jobs: | |
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
- name: Check build | ||
- name: Build | ||
run: | | ||
go version | ||
pwd && ls -l | ||
|
@@ -32,6 +32,21 @@ jobs: | |
--with $MODULE_NAME="." | ||
./k6ext version | ||
- name: Test | ||
if: ${{ github.ref_name == 'main' }} | ||
run: go test -count 1 -coverprofile=coverage.txt ./... | ||
|
||
- name: Upload Coverage | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: grafana/xk6-sql | ||
|
||
- name: Generate Go Report Card | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: creekorful/[email protected] | ||
|
||
test: | ||
strategy: | ||
fail-fast: false | ||
|
@@ -51,18 +66,3 @@ jobs: | |
which go | ||
go version | ||
go test -race -timeout 60s ./... | ||
- name: Coverage Test | ||
if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} | ||
run: go test -count 1 -coverprofile=coverage.txt ./... | ||
|
||
- name: Upload Coverage | ||
if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: grafana/xk6-sql | ||
|
||
- name: Generate Go Report Card | ||
if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} | ||
uses: creekorful/[email protected] |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/xk6-sql/sql" | ||
"github.com/stretchr/testify/require" | ||
"go.k6.io/k6/ext" | ||
) | ||
|
||
func Test_register(t *testing.T) { | ||
t.Parallel() | ||
|
||
require.Contains(t, ext.Get(ext.JSExtension), sql.ImportPath) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/sobek" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOpen(t *testing.T) { //nolint: paralleltest | ||
mod := New().NewModuleInstance(nil).(*module) | ||
|
||
driver := RegisterDriver("ramsql") | ||
require.NotNil(t, driver) | ||
|
||
db, err := mod.Open(driver, "") | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
|
||
_, err = mod.Open(sobek.New().ToValue("foo"), "testdb") // not a Symbol | ||
|
||
require.Error(t, err) | ||
|
||
_, err = mod.Open(sobek.NewSymbol("ramsql"), "testdb") // not a registered Symbol | ||
|
||
require.Error(t, err) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sqltest_test | ||
|
||
import ( | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/grafana/xk6-sql/sql" | ||
"github.com/grafana/xk6-sql/sqltest" | ||
|
||
_ "github.com/proullon/ramsql/driver" | ||
) | ||
|
||
//go:embed testdata/script.js | ||
var script string | ||
|
||
func TestRunScript(t *testing.T) { | ||
t.Parallel() | ||
|
||
sql.RegisterModule("ramsql") | ||
|
||
sqltest.RunScript(t, "ramsql", "testdb", 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 integer PRIMARY KEY AUTOINCREMENT, name varchar NOT NULL, value varchar);"); | ||
|
||
for (let i = 0; i < 5; i++) { | ||
db.exec("INSERT INTO test_table (name, value) VALUES ('name-" + i + "', 'value-" + i + "');"); | ||
} | ||
|
||
let all_rows = db.query("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 = db.query("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 = db.query("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(); |