Created
April 11, 2022 07:24
-
-
Save Sa1Gur/f9f0521e4679c06d66f489885ce95b9c to your computer and use it in GitHub Desktop.
script.js
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
import http from 'k6/http'; | |
import { check, sleep } from 'k6'; | |
export const options = { | |
stages: [ | |
{ duration: '1s', target: 100 }, | |
{ duration: '30s', target: 20 }, | |
{ duration: '1m30s', target: 10 }, | |
{ duration: '20s', target: 0 }, | |
], | |
}; | |
import { authenticateUsingIdentityServer } from './oauth/identity.js'; | |
function getRandomInt(max) { | |
return Math.floor(Math.random() * max); | |
} | |
export function setup() { | |
const passwordAuthResp = authenticateUsingIdentityServer( | |
'localhost', | |
'clientid', | |
'profile email openid roles', | |
{ | |
username: 'admin', | |
password: 'password' | |
} | |
); | |
console.log(JSON.stringify(passwordAuthResp)); | |
return passwordAuthResp; | |
} | |
export default function (data) { | |
const endpoin = 'https://endpoint'; | |
const payload = JSON.stringify({ | |
query: "", | |
variables: "", | |
}); | |
const params = { | |
headers: { | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer ${data.access_token}`, | |
}, | |
}; | |
const res = http.post(url, payload, params); | |
console.log(JSON.stringify(res.json())); | |
check(res, { 'status was 200': (r) => r.status == 200 }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment