mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
2ac1bfcc79
* Datasource/CloudWatch: More robust handling of different query modes A small refactor which changes how the CloudWatch datasource handles multiple queries with different query modes. Groundwork for future Logs/Metrics unification work.
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { CloudWatchDatasource } from './datasource';
|
|
import { TemplateSrv } from '../../../features/templating/template_srv';
|
|
import { setBackendSrv } from '@grafana/runtime';
|
|
import { DataQueryResponse, DefaultTimeRange } from '@grafana/data';
|
|
|
|
describe('datasource', () => {
|
|
describe('query', () => {
|
|
it('should return error if log query and log groups is not specified', async () => {
|
|
const { datasource } = setup();
|
|
const response: DataQueryResponse = (await datasource
|
|
.query({
|
|
targets: [
|
|
{
|
|
queryMode: 'Logs' as 'Logs',
|
|
},
|
|
],
|
|
} as any)
|
|
.toPromise()) as any;
|
|
expect(response.error?.message).toBe('Log group is required');
|
|
});
|
|
|
|
it('should return empty response if queries are hidden', async () => {
|
|
const { datasource } = setup();
|
|
const response: DataQueryResponse = (await datasource
|
|
.query({
|
|
targets: [
|
|
{
|
|
queryMode: 'Logs' as 'Logs',
|
|
hide: true,
|
|
},
|
|
],
|
|
} as any)
|
|
.toPromise()) as any;
|
|
expect(response.data).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('describeLogGroup', () => {
|
|
it('replaces region correctly in the query', async () => {
|
|
const { datasource, datasourceRequestMock } = setup();
|
|
await datasource.describeLogGroups({ region: 'default' });
|
|
expect(datasourceRequestMock.mock.calls[0][0].data.queries[0].region).toBe('us-west-1');
|
|
|
|
await datasource.describeLogGroups({ region: 'eu-east' });
|
|
expect(datasourceRequestMock.mock.calls[1][0].data.queries[0].region).toBe('eu-east');
|
|
});
|
|
});
|
|
});
|
|
|
|
function setup() {
|
|
const datasource = new CloudWatchDatasource({ jsonData: { defaultRegion: 'us-west-1' } } as any, new TemplateSrv(), {
|
|
timeRange() {
|
|
return DefaultTimeRange;
|
|
},
|
|
} as any);
|
|
const datasourceRequestMock = jest.fn();
|
|
datasourceRequestMock.mockResolvedValue({ data: [] });
|
|
setBackendSrv({ datasourceRequest: datasourceRequestMock } as any);
|
|
|
|
return { datasource, datasourceRequestMock };
|
|
}
|