Skip to content

Commit

Permalink
add test data k6 code
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanvancea committed Apr 24, 2024
1 parent 6775b7b commit a0e4668
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
16 changes: 16 additions & 0 deletions k6-test-data/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import http from 'k6/http';

export const options = {
vus: 3,
duration: '3s',
};

const usernames = ['user1','user3','admin'];
const passwords = ['123123','qwerty','qweqweqwe'];

export default function () {
http.get('https://test-api.k6.io/public/crocodiles/');
let random = Math.floor(Math.random() * usernames.length);

console.log(`username: ${usernames[random]}, psw: ${passwords[random]}`);
}
18 changes: 18 additions & 0 deletions k6-test-data/csv-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import http from 'k6/http';

import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';

const csvData = papaparse.parse(open('data.csv'), {header: true}).data;

export const options = {
vus: 3,
duration: '3s',
};

export default function () {
http.get('https://test-api.k6.io/public/crocodiles/');

let random = Math.floor(Math.random() * csvData.length);

console.log(`username: ${csvData[random].username}, psw: ${csvData[random].password}`);
}
4 changes: 4 additions & 0 deletions k6-test-data/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
username,password
user,123456
johndoe,qwerty
admin,123qwe123
6 changes: 6 additions & 0 deletions k6-test-data/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"users": [
{ "username": "json_admin", "password": "123456" },
{ "username": "json_test", "password": "qwerty" }
]
}
16 changes: 16 additions & 0 deletions k6-test-data/json-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import http from 'k6/http';

const jsonData = JSON.parse(open('./data.json')).users;

export const options = {
vus: 3,
duration: '3s',
};

export default function () {
http.get('https://test-api.k6.io/public/crocodiles/');

let random = Math.floor(Math.random() * jsonData.length);

console.log(`username: ${jsonData[random].username}, psw: ${jsonData[random].password}`);
}
20 changes: 20 additions & 0 deletions k6-test-data/shared-array-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import http from 'k6/http';
import {SharedArray} from 'k6/data';

const sharedData = new SharedArray("Shared Credentials", function(){
let data = JSON.parse(open('./data.json')).users;
return data;
})

export const options = {
vus: 3,
duration: '3s',
};

export default function () {
http.get('https://test-api.k6.io/public/crocodiles/');

let random = Math.floor(Math.random() * sharedData.length);

console.log(`username: ${sharedData[random].username}, psw: ${sharedData[random].password}`);
}
10 changes: 10 additions & 0 deletions k6-test-data/template-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import http from 'k6/http';

export const options = {
vus: 3,
duration: '3s',
};

export default function () {
http.get('https://test-api.k6.io/public/crocodiles/');
}

0 comments on commit a0e4668

Please sign in to comment.