|
@@ -1,5 +1,6 @@
|
|
|
-import moment from 'moment';
|
|
|
|
|
import LokiDatasource from './datasource';
|
|
import LokiDatasource from './datasource';
|
|
|
|
|
+import { LokiQuery } from './types';
|
|
|
|
|
+import { getQueryOptions } from 'test/helpers/getQueryOptions';
|
|
|
|
|
|
|
|
describe('LokiDatasource', () => {
|
|
describe('LokiDatasource', () => {
|
|
|
const instanceSettings: any = {
|
|
const instanceSettings: any = {
|
|
@@ -14,19 +15,13 @@ describe('LokiDatasource', () => {
|
|
|
replace: a => a,
|
|
replace: a => a,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const range = {
|
|
|
|
|
- from: moment(),
|
|
|
|
|
- to: moment(),
|
|
|
|
|
- raw: {
|
|
|
|
|
- from: 'now-6h',
|
|
|
|
|
- to: 'now'
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
test('should use default max lines when no limit given', () => {
|
|
test('should use default max lines when no limit given', () => {
|
|
|
const ds = new LokiDatasource(instanceSettings, backendSrvMock, templateSrvMock);
|
|
const ds = new LokiDatasource(instanceSettings, backendSrvMock, templateSrvMock);
|
|
|
backendSrvMock.datasourceRequest = jest.fn();
|
|
backendSrvMock.datasourceRequest = jest.fn();
|
|
|
- ds.query({ range, targets: [{ expr: 'foo', refId: 'B' }] });
|
|
|
|
|
|
|
+ const options = getQueryOptions<LokiQuery>({ targets: [{ expr: 'foo', refId: 'B' }] });
|
|
|
|
|
+
|
|
|
|
|
+ ds.query(options);
|
|
|
|
|
+
|
|
|
expect(backendSrvMock.datasourceRequest.mock.calls.length).toBe(1);
|
|
expect(backendSrvMock.datasourceRequest.mock.calls.length).toBe(1);
|
|
|
expect(backendSrvMock.datasourceRequest.mock.calls[0][0].url).toContain('limit=1000');
|
|
expect(backendSrvMock.datasourceRequest.mock.calls[0][0].url).toContain('limit=1000');
|
|
|
});
|
|
});
|
|
@@ -36,7 +31,10 @@ describe('LokiDatasource', () => {
|
|
|
const customSettings = { ...instanceSettings, jsonData: customData };
|
|
const customSettings = { ...instanceSettings, jsonData: customData };
|
|
|
const ds = new LokiDatasource(customSettings, backendSrvMock, templateSrvMock);
|
|
const ds = new LokiDatasource(customSettings, backendSrvMock, templateSrvMock);
|
|
|
backendSrvMock.datasourceRequest = jest.fn();
|
|
backendSrvMock.datasourceRequest = jest.fn();
|
|
|
- ds.query({ range, targets: [{ expr: 'foo', refId: 'A' }] });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const options = getQueryOptions<LokiQuery>({ targets: [{ expr: 'foo', refId: 'B' }] });
|
|
|
|
|
+ ds.query(options);
|
|
|
|
|
+
|
|
|
expect(backendSrvMock.datasourceRequest.mock.calls.length).toBe(1);
|
|
expect(backendSrvMock.datasourceRequest.mock.calls.length).toBe(1);
|
|
|
expect(backendSrvMock.datasourceRequest.mock.calls[0][0].url).toContain('limit=20');
|
|
expect(backendSrvMock.datasourceRequest.mock.calls[0][0].url).toContain('limit=20');
|
|
|
});
|
|
});
|