-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
73 lines (63 loc) · 1.94 KB
/
script.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
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
// init context: importing modules
import http from 'k6/http';
import { sleep, check, group } from 'k6';
export const options = {
tags: {
testid: "backend"
},
stages: [
{
//duration: '10s', target: 3
duration: '20m', target: 2
}
]
}
// init context: global variables
const url = "http://backend:5050/clients";
// init context: define custom function
function displayUrl() {
console.log(url)
}
export default function () {
// Display base URL
displayUrl();
group('Clients management', (_) => {
// Client creation
let newClientDetails = JSON.stringify({
firstname: "Thomas__" + __ITER,
lastname: "Dupont"
})
const newClient = http.post(url, newClientDetails);
check(newClient, {
'is status 201': (r) => r.status === 201,
'is ID present': (r) => r.json().hasOwnProperty('id')
});
// Get clients list
const listClients = http.get(url).json();
check(listClients, { 'retrieved clients': (clients) => clients.length > 0});
// Get client details
const getClient = http.get(url+"/"+listClients[0].id);
check (getClient, {
'is status 200': (r) => r.status === 200
});
// Put client details
let newLastname = JSON.stringify({
lastname: "Dupond__" + __ITER
})
const putClient = http.get(url+"/"+listClients[0].id, newLastname);
check (putClient, {
'is status 200': (r) => r.status === 200
});
// Delete client
const deleteClient = http.del(url+"/"+listClients[0].id);
check (deleteClient, {
'is status 204': (r) => r.status === 204
});
// Get 404 Error
const notFound = http.get(url+"/client")
check (notFound, {
'is status 404': (r) => r.status === 404
});
sleep(1);
})
}