-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
117 lines (100 loc) · 2.99 KB
/
Copy pathscript.js
File metadata and controls
117 lines (100 loc) · 2.99 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import http from 'k6/http';
import { group, check } from 'k6';
// Mirrors the local "xargs -P 30" curl smoke test: a single sustained step
// at 30 concurrent virtual users. Keeps the JDK HttpServer well within the
// load level it's designed for — higher VU counts surface k6/keep-alive
// edge cases unrelated to the library's correctness.
export const options = {
stages: [
{ duration: '10s', target: 30 },
{ duration: '30s', target: 30 },
{ duration: '5s', target: 0 },
],
};
const exampleObjectRequest = {
id: 'some-id',
age: 42,
random: 'd5af5004-8b5a-4db6-838e-38be773eac34',
status: 'ERROR',
feelingGood: true,
aList: [ 'string', 'string' ],
anObject: {
id: 'some-id',
age: 42,
longNumber: 900,
nested: {
nestedValue: 43
}
},
aListOfObjects: [
{ value: 42 },
{ value: 43 }
],
aDate: '2025-03-02',
aDateTime: '2025-03-02T12:34:56Z'
};
const exampleListRequest = [
{ value: 42 },
{ value: 43 }
];
const objectBody = JSON.stringify(exampleObjectRequest);
const listBody = JSON.stringify(exampleListRequest);
function safeHasOwn(body, prop) {
try {
return JSON.parse(body).hasOwnProperty(prop);
} catch (_) {
return false;
}
}
export default function () {
group('get request', () => {
const url = 'http://localhost:8080/api/v1/data';
const res = http.get(url, { headers: { 'X-Name': 'Alotta' } });
check(res, {
'is status 200': (r) => r.status === 200,
'is response in JSON format': (r) => r.headers['Content-Type'] === 'application/json',
'id exists in response': (r) => safeHasOwn(r.body, 'id'),
});
});
group('post request', () => {
const url = 'http://localhost:8080/api/v1/data';
const res = http.post(url, objectBody, {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'is status 200': (r) => r.status === 200,
'is response in JSON format': (r) => r.headers['Content-Type'] === 'application/json',
'id exists in response': (r) => safeHasOwn(r.body, 'id'),
});
});
group('post list-of-objects request', () => {
const url = 'http://localhost:8080/api/v1/list/objects';
const res = http.post(url, listBody, {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'is status 200': (r) => r.status === 200,
});
});
group('get query params', () => {
const url = 'http://localhost:8080/api/v1/params/query?q1=data&q2=data';
const res = http.get(url);
check(res, {
'is status 200': (r) => r.status === 200,
});
});
group('get path params', () => {
const url = 'http://localhost:8080/api/v1/params/path/1234567890';
const res = http.get(url);
check(res, {
'is status 200': (r) => r.status === 200,
});
});
group('get with many path params', () => {
const url = 'http://localhost:8080/api/v1/params/path/1234567890/Justin/Case';
const res = http.get(url);
check(res, {
'is status 200': (r) => r.status === 200,
});
});
}