@ -50,6 +50,46 @@ describe('LokiDatasource', () => {
replace : ( a : string ) = > a ,
} as unknown ) as TemplateSrv ;
describe ( 'when creating range query' , ( ) = > {
let ds : LokiDatasource ;
let adjustIntervalSpy : jest.SpyInstance ;
beforeEach ( ( ) = > {
const customData = { . . . ( instanceSettings . jsonData || { } ) , maxLines : 20 } ;
const customSettings = { . . . instanceSettings , jsonData : customData } ;
ds = new LokiDatasource ( customSettings , backendSrv , templateSrvMock ) ;
adjustIntervalSpy = jest . spyOn ( ds , 'adjustInterval' ) ;
} ) ;
it ( 'should use default intervalMs if one is not provided' , ( ) = > {
const target = { expr : '{job="grafana"}' , refId : 'B' } ;
const raw = { from : 'now' , to : 'now-1h' } ;
const range = { from : dateTime ( ) , to : dateTime ( ) , raw : raw } ;
const options = {
range ,
} ;
const req = ds . createRangeQuery ( target , options ) ;
expect ( req . start ) . toBeDefined ( ) ;
expect ( req . end ) . toBeDefined ( ) ;
expect ( adjustIntervalSpy ) . toHaveBeenCalledWith ( 1000 , expect . anything ( ) ) ;
} ) ;
it ( 'should use provided intervalMs' , ( ) = > {
const target = { expr : '{job="grafana"}' , refId : 'B' } ;
const raw = { from : 'now' , to : 'now-1h' } ;
const range = { from : dateTime ( ) , to : dateTime ( ) , raw : raw } ;
const options = {
range ,
intervalMs : 2000 ,
} ;
const req = ds . createRangeQuery ( target , options ) ;
expect ( req . start ) . toBeDefined ( ) ;
expect ( req . end ) . toBeDefined ( ) ;
expect ( adjustIntervalSpy ) . toHaveBeenCalledWith ( 2000 , expect . anything ( ) ) ;
} ) ;
} ) ;
describe ( 'when running range query with fallback' , ( ) = > {
let ds : LokiDatasource ;
beforeEach ( ( ) = > {