forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth_key_test.js
81 lines (66 loc) · 2.15 KB
/
auth_key_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
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
import { sleep, check, group } from 'k6';
import { createClient, createBasicAuthClient, createBearerAuthClient } from './modules/client.js';
import { createTestOrgIfNotExists, createTestdataDatasourceIfNotExists } from './modules/util.js';
export let options = {
noCookiesReset: true,
};
let endpoint = __ENV.URL || 'http://localhost:3000';
let apiKey = __ENV.API_KEY;
if (!apiKey) {
throw new Error('This script requires the API key argument -k to be defined.');
}
const client = createBearerAuthClient(endpoint, apiKey);
export const setup = () => {
const authClient = createBearerAuthClient(endpoint, apiKey);
const orgId = createTestOrgIfNotExists(authClient);
authClient.withOrgId(orgId);
const datasourceId = createTestdataDatasourceIfNotExists(authClient);
return {
orgId,
datasourceId,
};
};
export default (data) => {
client.withOrgId(data.orgId);
group('API key test', () => {
if (__ITER === 0) {
group('user can access grafana instance with APIKey', () => {
let res = client.datasources.getAll();
check(res, {
'response status is 200': (r) => r.status === 200,
});
});
}
if (__ITER !== 0) {
group('batch tsdb requests', () => {
const batchCount = 20;
const requests = [];
const payload = {
from: '1547765247624',
to: '1547768847624',
queries: [
{
refId: 'A',
scenarioId: 'random_walk',
intervalMs: 10000,
maxDataPoints: 433,
datasourceId: data.datasourceId,
},
],
};
requests.push({ method: 'GET', url: '/api/annotations?dashboardId=2074&from=1548078832772&to=1548082432772' });
for (let n = 0; n < batchCount; n++) {
requests.push({ method: 'POST', url: '/api/ds/query', body: payload });
}
let responses = client.batch(requests);
for (let n = 0; n < batchCount; n++) {
check(responses[n], {
'response status is 200': (r) => r.status === 200,
});
}
});
}
});
sleep(5);
};
export const teardown = (data) => {};