Skip to content

Commit 236ea55

Browse files
committed
Add basic tests
1 parent 80c93a7 commit 236ea55

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { getIndicesUnassignedShardStats } from './get_indices_unassigned_shard_stats';
8+
9+
describe('getIndicesUnassignedShardStats', () => {
10+
it('should return the unassigned shard stats for indices', async () => {
11+
const indices = {
12+
12345: { status: 'red', unassigned: { primary: 1, replica: 0 } },
13+
6789: { status: 'yellow', unassigned: { primary: 0, replica: 1 } },
14+
absdf82: { status: 'green', unassigned: { primary: 0, replica: 0 } },
15+
};
16+
17+
const req = {
18+
server: {
19+
config: () => ({
20+
get: () => {},
21+
}),
22+
plugins: {
23+
elasticsearch: {
24+
getCluster: () => ({
25+
callWithRequest: () => ({
26+
aggregations: {
27+
indices: {
28+
buckets: Object.keys(indices).map(id => ({
29+
key: id,
30+
state: {
31+
primary: {
32+
buckets:
33+
indices[id].unassigned.primary || indices[id].unassigned.replica
34+
? [
35+
{
36+
key_as_string: indices[id].unassigned.primary
37+
? 'true'
38+
: 'false',
39+
doc_count: 1,
40+
},
41+
]
42+
: [],
43+
},
44+
},
45+
})),
46+
},
47+
},
48+
}),
49+
}),
50+
},
51+
},
52+
},
53+
};
54+
const esIndexPattern = '*';
55+
const cluster = {};
56+
const stats = await getIndicesUnassignedShardStats(req, esIndexPattern, cluster);
57+
expect(stats.indices).toEqual(indices);
58+
});
59+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { getNodesShardCount } from './get_nodes_shard_count';
8+
9+
describe('getNodeShardCount', () => {
10+
it('should return the shard count per node', async () => {
11+
const nodes = {
12+
12345: { shardCount: 10 },
13+
6789: { shardCount: 1 },
14+
absdf82: { shardCount: 20 },
15+
};
16+
17+
const req = {
18+
server: {
19+
config: () => ({
20+
get: () => {},
21+
}),
22+
plugins: {
23+
elasticsearch: {
24+
getCluster: () => ({
25+
callWithRequest: () => ({
26+
aggregations: {
27+
nodes: {
28+
buckets: Object.keys(nodes).map(id => ({
29+
key: id,
30+
doc_count: nodes[id].shardCount,
31+
})),
32+
},
33+
},
34+
}),
35+
}),
36+
},
37+
},
38+
},
39+
};
40+
const esIndexPattern = '*';
41+
const cluster = {};
42+
const counts = await getNodesShardCount(req, esIndexPattern, cluster);
43+
expect(counts.nodes).toEqual(nodes);
44+
});
45+
});

0 commit comments

Comments
 (0)