-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-test-add-book.js
More file actions
76 lines (59 loc) · 1.69 KB
/
Copy pathapi-test-add-book.js
File metadata and controls
76 lines (59 loc) · 1.69 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
import { check, group } from 'k6';
import http from 'k6/http';
import { Counter } from 'k6/metrics';
export const options = {
stages: [
{ duration: '10s', target: 20 }, // simulate ramp-up of traffic from 1 to 20 users over 10 seconds.
{ duration: '50s', target: 20 }, // stay at 20 users for 50 seconds
]
};
// Custom counters for V1 and V2 requests
const v1Requests = new Counter('v1_requests');
const v2Requests = new Counter('v2_requests');
function testV1() {
const url = 'http://localhost:5299/v1/books';
const request = {
title: '',
author: ''
};
const response = http.post(url, JSON.stringify(request), {
headers: {
'Content-Type': 'application/json',
},
});
v1Requests.add(1);
check(response, {
'V1: response code was 400': (response) => response.status === 400,
});
}
function testV2() {
const url = 'http://localhost:5299/v2/books/';
const request = {
title: '',
author: ''
};
const response = http.post(url, JSON.stringify(request), {
headers: {
'Content-Type': 'application/json',
},
});
v2Requests.add(1);
check(response, {
'V2: response code was 400': (response) => response.status === 400,
});
}
export default function () {
group('Test V1 Endpoints', function () {
testV1();
});
group('Test V2 Endpoints', function () {
testV2();
});
}
//export default function () {
// const url = 'http://localhost:5299/books/5';
// const response = http.get(url);
// check(response, {
// 'response code was 404': (response) => response.status === 404,
// });
//}