|
|
@ -1474,26 +1474,26 @@ describe('LokiDatasource', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('ignores invalid queries', () => { |
|
|
|
it('ignores invalid queries', () => { |
|
|
|
const spy = jest.spyOn(ds, 'query'); |
|
|
|
const spy = jest.spyOn(ds, 'query'); |
|
|
|
ds.getDataSamples({ expr: 'not a query', refId: 'A' }); |
|
|
|
ds.getDataSamples({ expr: 'not a query', refId: 'A' }, mockTimeRange); |
|
|
|
expect(spy).not.toHaveBeenCalled(); |
|
|
|
expect(spy).not.toHaveBeenCalled(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('ignores metric queries', () => { |
|
|
|
it('ignores metric queries', () => { |
|
|
|
const spy = jest.spyOn(ds, 'query'); |
|
|
|
const spy = jest.spyOn(ds, 'query'); |
|
|
|
ds.getDataSamples({ expr: 'count_over_time({a="b"}[1m])', refId: 'A' }); |
|
|
|
ds.getDataSamples({ expr: 'count_over_time({a="b"}[1m])', refId: 'A' }, mockTimeRange); |
|
|
|
expect(spy).not.toHaveBeenCalled(); |
|
|
|
expect(spy).not.toHaveBeenCalled(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('uses the current interval in the request', () => { |
|
|
|
it('uses the current interval in the request', () => { |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }, mockTimeRange); |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect.objectContaining({ |
|
|
|
expect.objectContaining({ |
|
|
|
range: ds.getTimeRange(), |
|
|
|
range: mockTimeRange, |
|
|
|
}) |
|
|
|
}) |
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('hides the request from the inspector', () => { |
|
|
|
it('hides the request from the inspector', () => { |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }, mockTimeRange); |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect.objectContaining({ |
|
|
|
expect.objectContaining({ |
|
|
|
hideFromInspector: true, |
|
|
|
hideFromInspector: true, |
|
|
@ -1503,7 +1503,7 @@ describe('LokiDatasource', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('sets the supporting query type in the request', () => { |
|
|
|
it('sets the supporting query type in the request', () => { |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse)); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }); |
|
|
|
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' }, mockTimeRange); |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect(spy).toHaveBeenCalledWith( |
|
|
|
expect.objectContaining({ |
|
|
|
expect.objectContaining({ |
|
|
|
targets: [expect.objectContaining({ supportingQueryType: SupportingQueryType.DataSample })], |
|
|
|
targets: [expect.objectContaining({ supportingQueryType: SupportingQueryType.DataSample })], |
|
|
@ -1828,18 +1828,18 @@ describe('makeStatsRequest', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('getTimeRange*()', () => { |
|
|
|
describe('getTimeRangeParams()', () => { |
|
|
|
it('exposes the current time range', () => { |
|
|
|
it('turns time range into a Loki range parameters', () => { |
|
|
|
const ds = createLokiDatasource(); |
|
|
|
const ds = createLokiDatasource(); |
|
|
|
const timeRange = ds.getTimeRange(); |
|
|
|
const range = { |
|
|
|
|
|
|
|
from: dateTime(1524650400000), |
|
|
|
expect(timeRange.from).toBeDefined(); |
|
|
|
to: dateTime(1524654000000), |
|
|
|
expect(timeRange.to).toBeDefined(); |
|
|
|
raw: { |
|
|
|
}); |
|
|
|
from: 'now-1h', |
|
|
|
|
|
|
|
to: 'now', |
|
|
|
it('exposes time range as params', () => { |
|
|
|
}, |
|
|
|
const ds = createLokiDatasource(); |
|
|
|
}; |
|
|
|
const params = ds.getTimeRangeParams(); |
|
|
|
const params = ds.getTimeRangeParams(range); |
|
|
|
|
|
|
|
|
|
|
|
// Returns a very big integer, so we stringify it for the assertion
|
|
|
|
// Returns a very big integer, so we stringify it for the assertion
|
|
|
|
expect(JSON.stringify(params)).toEqual('{"start":1524650400000000000,"end":1524654000000000000}'); |
|
|
|
expect(JSON.stringify(params)).toEqual('{"start":1524650400000000000,"end":1524654000000000000}'); |
|
|
|