The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/elasticsearch/utils.test.ts

58 lines
1.6 KiB

import { removeEmpty, coerceESVersion } from './utils';
describe('removeEmpty', () => {
it('Should remove all empty', () => {
const original = {
stringsShouldBeKept: 'Something',
unlessTheyAreEmpty: '',
nullToBeRemoved: null,
undefinedToBeRemoved: null,
zeroShouldBeKept: 0,
booleansShouldBeKept: false,
emptyObjectsShouldBeRemoved: {},
emptyArrayShouldBeRemoved: [],
nonEmptyArraysShouldBeKept: [1, 2, 3],
nestedObjToBeRemoved: {
toBeRemoved: undefined,
},
nestedObjectToKeep: {
thisShouldBeRemoved: null,
thisShouldBeKept: 'Hello, Grafana',
},
};
const expectedResult = {
stringsShouldBeKept: 'Something',
zeroShouldBeKept: 0,
booleansShouldBeKept: false,
nonEmptyArraysShouldBeKept: [1, 2, 3],
nestedObjectToKeep: {
thisShouldBeKept: 'Hello, Grafana',
},
};
expect(removeEmpty(original)).toStrictEqual(expectedResult);
});
it('should correctly coerce the version info', () => {
// valid string
expect(coerceESVersion('8.1.3')).toBe('8.1.3');
// invalid string
expect(coerceESVersion('haha')).toBe('8.0.0');
// known number
expect(coerceESVersion(2)).toBe('2.0.0');
expect(coerceESVersion(5)).toBe('5.0.0');
expect(coerceESVersion(56)).toBe('5.6.0');
expect(coerceESVersion(60)).toBe('6.0.0');
expect(coerceESVersion(70)).toBe('7.0.0');
expect(coerceESVersion(8)).toBe('8.0.0');
// unknown number
expect(coerceESVersion(42)).toBe('8.0.0');
// undefined
expect(coerceESVersion(undefined)).toBe('8.0.0');
});
});