-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshort_link_test.js
40 lines (34 loc) · 913 Bytes
/
short_link_test.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
import { check } from "k6";
import http from "k6/http";
export const options = {
stages: [{ duration: "1m", target: 100 }],
thresholds: {
iterations: ["rate > 100"],
},
};
export function testCreate(longurl) {
var url = `http://${__ENV.HOSTNAME}/link`;
var payload = JSON.stringify({
url: longurl,
});
var params = {
headers: {
"Content-Type": "application/json",
},
};
var r = http.post(url, payload, params);
return r;
}
export function testGetRedirect(shortLink, longurl) {
const r = http.get(shortLink, { redirects: 0 });
check(r, {
"is redirect": (r) => r.status === 302,
"is valid url": (r) => r.headers.Location === longurl,
});
}
export default function () {
const longurl = `https://www.google.com/?q=vu%20${__VU},iter%20${__ITER}`;
var r = testCreate(longurl);
const shortLink = r.json('link');
testGetRedirect(shortLink, longurl)
}