-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
scroll_count.ts
153 lines (136 loc) · 4.44 KB
/
scroll_count.ts
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { SuperTest, Test } from 'supertest';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
const apiUrl = '/api/kibana/management/saved_objects/scroll/counts';
const defaultTypes = ['visualization', 'index-pattern', 'search', 'dashboard'];
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest') as SuperTest<Test>;
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');
describe('scroll_count', () => {
describe('with less than 10k objects', () => {
before(async () => {
await kibanaServer.savedObjects.cleanStandardList();
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/scroll_count.json'
);
});
after(async () => {
await kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/scroll_count.json'
);
await kibanaServer.savedObjects.cleanStandardList();
});
it('returns the count for each included types', async () => {
const res = await supertest
.post(apiUrl)
.send({
typesToInclude: defaultTypes,
})
.expect(200);
expect(res.body).to.eql({
dashboard: 2,
'index-pattern': 1,
search: 1,
visualization: 2,
});
});
it('only returns count for types to include', async () => {
const res = await supertest
.post(apiUrl)
.send({
typesToInclude: ['dashboard', 'search'],
})
.expect(200);
expect(res.body).to.eql({
dashboard: 2,
search: 1,
});
});
it('filters on title when `searchString` is provided', async () => {
const res = await supertest
.post(apiUrl)
.send({
typesToInclude: defaultTypes,
searchString: 'Amazing',
})
.expect(200);
expect(res.body).to.eql({
dashboard: 1,
visualization: 1,
'index-pattern': 0,
search: 0,
});
});
it('includes all requested types even when none match the search', async () => {
const res = await supertest
.post(apiUrl)
.send({
typesToInclude: ['dashboard', 'search', 'visualization'],
searchString: 'nothing-will-match',
})
.expect(200);
expect(res.body).to.eql({
dashboard: 0,
visualization: 0,
search: 0,
});
});
});
describe('scroll_count with more than 10k objects', () => {
const importVisualizations = async ({
startIdx = 1,
endIdx,
}: {
startIdx?: number;
endIdx: number;
}) => {
const fileChunks: string[] = [];
for (let i = startIdx; i <= endIdx; i++) {
const id = `test-vis-${i}`;
fileChunks.push(
JSON.stringify({
type: 'visualization',
id,
attributes: {
title: `My visualization (${i})`,
uiStateJSON: '{}',
visState: '{}',
},
references: [],
})
);
}
await supertest
.post(`/api/saved_objects/_import`)
.attach('file', Buffer.from(fileChunks.join('\n'), 'utf8'), 'export.ndjson')
.expect(200);
};
before(async () => {
await importVisualizations({ startIdx: 1, endIdx: 6000 });
await importVisualizations({ startIdx: 6001, endIdx: 12000 });
});
after(async () => {
await esArchiver.emptyKibanaIndex();
});
it('returns the correct count for each included types', async () => {
const res = await supertest
.post(apiUrl)
.send({
typesToInclude: ['visualization'],
})
.expect(200);
expect(res.body).to.eql({
visualization: 12000,
});
});
});
});
}