-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
78 lines (70 loc) · 2.55 KB
/
test.js
File metadata and controls
78 lines (70 loc) · 2.55 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-disable no-console */
import http from 'k6/http';
import { check, group } from 'k6';
import * as customMetrics from './helpers/custom_metrics.js';
import * as payload from './helpers/payload.js';
import { baseURL, metricTags, path } from './helpers/global_variable.js';
import { request } from './data/request.js';
/* Test Scenario */
export function groupGET() {
group('Load Test - Method GET Request', function () {
// http-request(1)
const data = payload.getPayload(metricTags.getUsers);
const response = http.get(`${baseURL}${path.getUsers}`, data.params);
let parsedResponse;
try {
parsedResponse = JSON.parse(response.body);
} catch (e) {
if (parsedResponse == undefined) parsedResponse = { page: '' };
console.error(`${path.getUsers} | Response is not a JSON`);
console.error(JSON.stringify(response.body));
}
// validate-response
const checkResponse = check(response, {
[path.getUsers]: response.status === 200 && parsedResponse.page === 2
});
if (!checkResponse) {
if (response.status != 200) {
customMetrics.httpNot200.add(1, metricTags.getUsers);
console.error((`${path.getUsers} | HTTP Response: ${response.status}`));
}
customMetrics.iterationFailed.add(1);
customMetrics.errorRate.add(true);
console.error(`${path.getUsers} | ${JSON.stringify(parsedResponse)}`);
} else {
customMetrics.iterationSuccess.add(1);
customMetrics.errorRate.add(false);
}
});
}
export function groupPOST() {
group('Load Test - Method POST Request', function () {
// http-request(1)
const data = payload.postPayload(request.email, request.password, metricTags.login);
const response = http.post(`${baseURL}${path.login}`, data.body, data.params);
let parsedResponse;
try {
parsedResponse = JSON.parse(response.body);
} catch (e) {
if (parsedResponse == undefined) parsedResponse = { token: '' };
console.error(`${path.login} | Response is not a JSON`);
console.error(JSON.stringify(response.body));
}
// validate-response
const checkResponse = check(response, {
[path.login]: response.status === 200 && parsedResponse.token === 'QpwL5tke4Pnpja7X4'
});
if (!checkResponse) {
if (response.status != 200) {
customMetrics.httpNot200.add(1, metricTags.login);
console.error((`${path.login} | HTTP Response: ${response.status}`));
}
customMetrics.iterationFailed.add(1);
customMetrics.errorRate.add(true);
console.error(`${path.login} | ${JSON.stringify(parsedResponse)}`);
} else {
customMetrics.iterationSuccess.add(1);
customMetrics.errorRate.add(false);
}
});
}