Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 6, 2020
1 parent 80c93a7 commit 236ea55
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getIndicesUnassignedShardStats } from './get_indices_unassigned_shard_stats';

describe('getIndicesUnassignedShardStats', () => {
it('should return the unassigned shard stats for indices', async () => {
const indices = {
12345: { status: 'red', unassigned: { primary: 1, replica: 0 } },
6789: { status: 'yellow', unassigned: { primary: 0, replica: 1 } },
absdf82: { status: 'green', unassigned: { primary: 0, replica: 0 } },
};

const req = {
server: {
config: () => ({
get: () => {},
}),
plugins: {
elasticsearch: {
getCluster: () => ({
callWithRequest: () => ({
aggregations: {
indices: {
buckets: Object.keys(indices).map(id => ({
key: id,
state: {
primary: {
buckets:
indices[id].unassigned.primary || indices[id].unassigned.replica
? [
{
key_as_string: indices[id].unassigned.primary
? 'true'
: 'false',
doc_count: 1,
},
]
: [],
},
},
})),
},
},
}),
}),
},
},
},
};
const esIndexPattern = '*';
const cluster = {};
const stats = await getIndicesUnassignedShardStats(req, esIndexPattern, cluster);
expect(stats.indices).toEqual(indices);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getNodesShardCount } from './get_nodes_shard_count';

describe('getNodeShardCount', () => {
it('should return the shard count per node', async () => {
const nodes = {
12345: { shardCount: 10 },
6789: { shardCount: 1 },
absdf82: { shardCount: 20 },
};

const req = {
server: {
config: () => ({
get: () => {},
}),
plugins: {
elasticsearch: {
getCluster: () => ({
callWithRequest: () => ({
aggregations: {
nodes: {
buckets: Object.keys(nodes).map(id => ({
key: id,
doc_count: nodes[id].shardCount,
})),
},
},
}),
}),
},
},
},
};
const esIndexPattern = '*';
const cluster = {};
const counts = await getNodesShardCount(req, esIndexPattern, cluster);
expect(counts.nodes).toEqual(nodes);
});
});

0 comments on commit 236ea55

Please sign in to comment.