Skip to content

Commit

Permalink
Handles unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Jun 26, 2020
1 parent 3e62592 commit 345310c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export interface NodesFeatureUsageResponse {

export type NodesUsageFetcher = (callCluster: APICaller) => Promise<NodesFeatureUsageResponse>;

export type NodesUsageGetter = (callCluster: APICaller) => Promise<{ nodes: NodeObj[] }>;
export type NodesUsageGetter = (
callCluster: APICaller
) => Promise<{ nodes: NodeObj[] | Array<{}> }>;
/**
* Get the nodes usage data from the connected cluster.
*
Expand All @@ -75,9 +77,12 @@ export async function fetchNodesUsage<NodesUsageFetcher>(callCluster: APICaller)
*/
export const getNodesUsage: NodesUsageGetter = async (callCluster) => {
const result = await fetchNodesUsage<NodesUsageFetcher>(callCluster);
const transformedNodes = Object.entries(result.nodes).map(([key, value]) => ({
...(value as NodeObj),
node_id: key,
}));
let transformedNodes = [{}];
if (result && result.nodes) {
transformedNodes = Object.entries(result.nodes).map(([key, value]) => ({
...(value as NodeObj),
node_id: key,
}));
}
return { nodes: transformedNodes };
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ const kibana = {
rain: { chances: 2 },
snow: { chances: 0 },
};
const nodesUsage = {
some_node_id: {
timestamp: 1588617023177,
since: 1588616945163,
rest_actions: {
nodes_usage_action: 1,
},
aggregations: {
terms: {
bytes: 2,
},
},
},
};

const getContext = () => ({
version: '8675309-snapshot',
Expand All @@ -47,6 +61,11 @@ describe('Telemetry Collection: Get Aggregated Stats', () => {
if (options.path === '/_license' || options.path === '/_xpack/usage') {
// eslint-disable-next-line no-throw-literal
throw { statusCode: 404 };
} else if (options.path === '/_nodes/usage') {
return {
cluster_name: 'test cluster',
nodes: nodesUsage,
};
}
return {};
case 'info':
Expand Down Expand Up @@ -81,6 +100,12 @@ describe('Telemetry Collection: Get Aggregated Stats', () => {
if (options.path === '/_xpack/usage') {
return {};
}
if (options.path === '/_nodes/usage') {
return {
cluster_name: 'test cluster',
nodes: nodesUsage,
};
}
case 'info':
return { cluster_uuid: 'test', cluster_name: 'test', version: { number: '8.0.0' } };
default:
Expand Down

0 comments on commit 345310c

Please sign in to comment.