mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 08:18:10 -05:00
114 lines
4.0 KiB
TypeScript
114 lines
4.0 KiB
TypeScript
import { StackdriverAggregationCtrl } from '../query_aggregation_ctrl';
|
|
|
|
describe('StackdriverAggregationCtrl', () => {
|
|
let ctrl;
|
|
describe('aggregation and alignment options', () => {
|
|
describe('when new query result is returned from the server', () => {
|
|
describe('and result is double and gauge and no group by is used', () => {
|
|
beforeEach(async () => {
|
|
ctrl = new StackdriverAggregationCtrl(
|
|
{
|
|
$on: () => {},
|
|
target: {
|
|
valueType: 'DOUBLE',
|
|
metricKind: 'GAUGE',
|
|
aggregation: { crossSeriesReducer: '', groupBys: [] },
|
|
},
|
|
},
|
|
{
|
|
replace: s => s,
|
|
variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }],
|
|
}
|
|
);
|
|
});
|
|
|
|
it('should populate all aggregate options except two', () => {
|
|
ctrl.setAggOptions();
|
|
const [aggOptionsGroup] = ctrl.aggOptions;
|
|
expect(aggOptionsGroup.options.length).toBe(11);
|
|
expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
|
|
expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
|
|
);
|
|
});
|
|
|
|
it('should populate all alignment options except two', () => {
|
|
ctrl.setAlignOptions();
|
|
const [aggOptionsGroup] = ctrl.aggOptions;
|
|
expect(aggOptionsGroup.options.length).toBe(11);
|
|
expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
|
|
expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('and result is double and delta and no group by is used', () => {
|
|
beforeEach(async () => {
|
|
ctrl = new StackdriverAggregationCtrl(
|
|
{
|
|
$on: () => {},
|
|
target: {
|
|
valueType: 'DOUBLE',
|
|
metricKind: 'DELTA',
|
|
aggregation: { crossSeriesReducer: '', groupBys: [] },
|
|
},
|
|
},
|
|
{
|
|
replace: s => s,
|
|
variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }],
|
|
}
|
|
);
|
|
});
|
|
|
|
it('should populate all alignment options except four', () => {
|
|
ctrl.setAlignOptions();
|
|
const [alignOptionsGroup] = ctrl.alignOptions;
|
|
expect(alignOptionsGroup.options.length).toBe(9);
|
|
expect(alignOptionsGroup.options.map(o => o.value)).toEqual(
|
|
expect['not'].arrayContaining([
|
|
'ALIGN_NEXT_OLDER',
|
|
'ALIGN_INTERPOLATE',
|
|
'ALIGN_COUNT_TRUE',
|
|
'ALIGN_COUNT_FALSE',
|
|
'ALIGN_FRACTION_TRUE',
|
|
])
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('and result is double and gauge and a group by is used', () => {
|
|
beforeEach(async () => {
|
|
ctrl = new StackdriverAggregationCtrl(
|
|
{
|
|
$on: () => {},
|
|
target: {
|
|
valueType: 'DOUBLE',
|
|
metricKind: 'GAUGE',
|
|
aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
|
|
},
|
|
},
|
|
{
|
|
replace: s => s,
|
|
variables: [{ name: 'someVariable1' }],
|
|
}
|
|
);
|
|
});
|
|
|
|
it('should populate all aggregate options except three', () => {
|
|
ctrl.setAggOptions();
|
|
const [aggOptionsGroup] = ctrl.aggOptions;
|
|
expect(aggOptionsGroup.options.length).toBe(10);
|
|
expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
|
|
expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE'])
|
|
);
|
|
});
|
|
|
|
it('should select some other reducer than REDUCE_NONE', () => {
|
|
ctrl.setAggOptions();
|
|
expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('');
|
|
expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('REDUCE_NONE');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|