-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk6.js
35 lines (29 loc) · 947 Bytes
/
k6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import http from 'k6/http';
import { check, fail } from 'k6';
export default function () {
const url = 'https://postman-echo.com/post';
const payload = JSON.stringify({
username: 'someuser',
password: 'somepassword'
});
const params = {
headers: {
'Content-Type': 'application/json'
}
};
const res = http.post(url,payload,params);
const checkOutput = check(
res,
{
'response code was 200': (r) => r.status === 200,
'body size was less than 1234 bytes': (r) => r.body.length < 1234,
'body has username': (r) => r.body.includes('username'),
'body has password': (r) => r.body.includes('password'),
'headers has content json': (r) => r.headers['Content-Type'].includes('json'),
},
{ myTag: "I'm a tag" }
);
if (!checkOutput) {
fail('unexpected response');
}
}