2020-01-01 13:55:28 +05:30
|
|
|
import { normalizeMetric, uniqMetricsId } from '~/monitoring/stores/utils';
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
describe('normalizeMetric', () => {
|
|
|
|
[
|
|
|
|
{ args: [], expected: 'undefined_undefined' },
|
|
|
|
{ args: [undefined], expected: 'undefined_undefined' },
|
|
|
|
{ args: [{ id: 'something' }], expected: 'undefined_something' },
|
|
|
|
{ args: [{ id: 45 }], expected: 'undefined_45' },
|
|
|
|
{ args: [{ metric_id: 5 }], expected: '5_undefined' },
|
|
|
|
{ args: [{ metric_id: 'something' }], expected: 'something_undefined' },
|
|
|
|
{
|
|
|
|
args: [{ metric_id: 5, id: 'system_metrics_kubernetes_container_memory_total' }],
|
|
|
|
expected: '5_system_metrics_kubernetes_container_memory_total',
|
|
|
|
},
|
|
|
|
].forEach(({ args, expected }) => {
|
|
|
|
it(`normalizes metric to "${expected}" with args=${JSON.stringify(args)}`, () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(normalizeMetric(...args)).toEqual({ metric_id: expected, metricId: expected });
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('uniqMetricsId', () => {
|
|
|
|
[
|
|
|
|
{ input: { id: 1 }, expected: 'undefined_1' },
|
|
|
|
{ input: { metric_id: 2 }, expected: '2_undefined' },
|
|
|
|
{ input: { metric_id: 2, id: 21 }, expected: '2_21' },
|
|
|
|
{ input: { metric_id: 22, id: 1 }, expected: '22_1' },
|
|
|
|
{ input: { metric_id: 'aaa', id: '_a' }, expected: 'aaa__a' },
|
|
|
|
].forEach(({ input, expected }) => {
|
|
|
|
it(`creates unique metric ID with ${JSON.stringify(input)}`, () => {
|
|
|
|
expect(uniqMetricsId(input)).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|