Skip to content

Commit

Permalink
Add test files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 19, 2021
1 parent ef90801 commit 654e73e
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 { fetchElasticsearchVersions } from './fetch_elasticsearch_versions';

describe('fetchElasticsearchVersions', () => {
let callCluster = jest.fn();
const clusters = [
{
clusterUuid: 'cluster123',
clusterName: 'test-cluster',
},
];
const index = '.monitoring-es-*';
const size = 10;
const versions = ['8.0.0', '7.2.1'];

it('fetch as expected', async () => {
callCluster = jest.fn().mockImplementation(() => {
return {
hits: {
hits: [
{
_index: `Monitoring:${index}`,
_source: {
cluster_uuid: 'cluster123',
cluster_stats: {
nodes: {
versions,
},
},
},
},
],
},
};
});

const result = await fetchElasticsearchVersions(callCluster, clusters, index, size);
expect(result).toEqual([
{
clusterUuid: clusters[0].clusterUuid,
ccs: 'Monitoring',
versions,
},
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { fetchKibanaVersions } from './fetch_kibana_versions';

describe('fetchKibanaVersions', () => {
let callCluster = jest.fn();
const clusters = [
{
clusterUuid: 'cluster123',
clusterName: 'test-cluster',
},
];
const index = '.monitoring-kibana-*';
const size = 10;

it('fetch as expected', async () => {
callCluster = jest.fn().mockImplementation(() => {
return {
aggregations: {
index: {
buckets: [
{
key: `Monitoring:${index}`,
},
],
},
cluster: {
buckets: [
{
key: 'cluster123',
group_by_kibana: {
buckets: [
{
group_by_version: {
buckets: [
{
key: '8.0.0',
},
],
},
},
{
group_by_version: {
buckets: [
{
key: '7.2.1',
},
],
},
},
],
},
},
],
},
},
};
});

const result = await fetchKibanaVersions(callCluster, clusters, index, size);
expect(result).toEqual([
{
clusterUuid: clusters[0].clusterUuid,
ccs: 'Monitoring',
versions: ['8.0.0', '7.2.1'],
},
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { fetchLogstashVersions } from './fetch_logstash_versions';

describe('fetchLogstashVersions', () => {
let callCluster = jest.fn();
const clusters = [
{
clusterUuid: 'cluster123',
clusterName: 'test-cluster',
},
];
const index = '.monitoring-logstash-*';
const size = 10;

it('fetch as expected', async () => {
callCluster = jest.fn().mockImplementation(() => {
return {
aggregations: {
index: {
buckets: [
{
key: `Monitoring:${index}`,
},
],
},
cluster: {
buckets: [
{
key: 'cluster123',
group_by_logstash: {
buckets: [
{
group_by_version: {
buckets: [
{
key: '8.0.0',
},
],
},
},
{
group_by_version: {
buckets: [
{
key: '7.2.1',
},
],
},
},
],
},
},
],
},
},
};
});

const result = await fetchLogstashVersions(callCluster, clusters, index, size);
expect(result).toEqual([
{
clusterUuid: clusters[0].clusterUuid,
ccs: 'Monitoring',
versions: ['8.0.0', '7.2.1'],
},
]);
});
});

0 comments on commit 654e73e

Please sign in to comment.