-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: use more realistic examples from k6x
- Loading branch information
Showing
7 changed files
with
83 additions
and
37 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,13 @@ | ||
"use k6 >= 0.50"; | ||
"use k6 with k6/x/faker >= 0.3.0"; | ||
"use k6 with k6/x/sql >= 0.4.0"; | ||
|
||
import faker from "./faker.js"; | ||
import sqlite from "./sqlite.js"; | ||
|
||
export { setup, teardown } from "./sqlite.js"; | ||
|
||
export default () => { | ||
faker(); | ||
sqlite(); | ||
}; |
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,10 @@ | ||
// source: https://github.com/szkiba/xk6-faker/blob/v0.3.0/examples/custom-faker.js | ||
import { Faker } from "k6/x/faker"; | ||
|
||
const faker = new Faker(11); | ||
|
||
export default function () { | ||
console.log(faker.person.firstName()); | ||
} | ||
|
||
// output: Josiah |
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,24 @@ | ||
// source: https://github.com/grafana/xk6-sql/blob/v0.4.0/examples/sqlite3_test.js | ||
import sql from "k6/x/sql"; | ||
|
||
const db = sql.open("sqlite3", "./test.db"); | ||
|
||
export function setup() { | ||
db.exec(`CREATE TABLE IF NOT EXISTS keyvalues ( | ||
id integer PRIMARY KEY AUTOINCREMENT, | ||
key varchar NOT NULL, | ||
value varchar);`); | ||
} | ||
|
||
export function teardown() { | ||
db.close(); | ||
} | ||
|
||
export default function () { | ||
db.exec("INSERT INTO keyvalues (key, value) VALUES('plugin-name', 'k6-plugin-sql');"); | ||
|
||
let results = sql.query(db, "SELECT * FROM keyvalues WHERE key = $1;", "plugin-name"); | ||
for (const row of results) { | ||
console.log(`key: ${row.key}, value: ${row.value}`); | ||
} | ||
} |
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,36 @@ | ||
import { Faker } from "k6/x/faker"; | ||
import sql from "k6/x/sql"; | ||
|
||
const db = sql.open("sqlite3", "./test-users.db"); | ||
|
||
export function setup() { | ||
db.exec(` | ||
CREATE TABLE IF NOT EXISTS users ( | ||
sub varchar PRIMARY KEY, | ||
name varchar NOT NULL, | ||
email varchar NOT NULL | ||
);`); | ||
|
||
const faker = new Faker(11); | ||
|
||
db.exec(` | ||
INSERT OR REPLACE INTO users (sub, name, email) VALUES ( | ||
'${faker.internet.username()}', | ||
'${faker.person.firstName()} ${faker.person.lastName()}', | ||
'${faker.person.email()}' | ||
);`); | ||
} | ||
|
||
export function teardown() { | ||
db.close(); | ||
} | ||
|
||
export default function () { | ||
const results = sql.query(db, "SELECT * FROM users"); | ||
|
||
for (const row of results) { | ||
const { sub, name, email } = row; | ||
|
||
console.log({ sub, name, email }); | ||
} | ||
} |