From 34d9274c4cb4c2ce5d480ee756d621bf91bad021 Mon Sep 17 00:00:00 2001 From: Lukas Siatka Date: Tue, 7 Jan 2020 15:15:33 +0100 Subject: [PATCH] Datasource: fixes prometheus datasource tests - adds align range --- .../datasource/prometheus/datasource.test.ts | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.test.ts b/public/app/plugins/datasource/prometheus/datasource.test.ts index 5a2ddcdcbf2..c9c9047701f 100644 --- a/public/app/plugins/datasource/prometheus/datasource.test.ts +++ b/public/app/plugins/datasource/prometheus/datasource.test.ts @@ -1134,7 +1134,17 @@ describe('PrometheusDatasource', () => { let end = 7 * 24 * 60 * 60; end -= end % 55; const start = 0; - const urlExpected = 'proxied/api/v1/query_range?query=test' + '&start=' + start + '&end=' + end + '&step=55'; + const step = 55; + const adjusted = alignRange( + start, + end, + step, + getTimeSrv() + .timeRange() + .to.utcOffset() * 60 + ); + const urlExpected = + 'proxied/api/v1/query_range?query=test' + '&start=' + adjusted.start + '&end=' + adjusted.end + '&step=' + step; getBackendSrvMock().datasourceRequest = jest.fn(() => Promise.resolve(response)); ds.query(query as any); const res = (getBackendSrvMock().datasourceRequest as jest.Mock).mock.calls[0][0]; @@ -1384,14 +1394,24 @@ describe('PrometheusDatasource', () => { let end = 7 * 24 * 60 * 60; end -= end % 55; const start = 0; + const step = 55; + const adjusted = alignRange( + start, + end, + step, + getTimeSrv() + .timeRange() + .to.utcOffset() * 60 + ); const urlExpected = 'proxied/api/v1/query_range?query=' + encodeURIComponent('rate(test[$__interval])') + '&start=' + - start + + adjusted.start + '&end=' + - end + - '&step=55'; + adjusted.end + + '&step=' + + step; getBackendSrvMock().datasourceRequest = jest.fn(() => Promise.resolve(response)); templateSrv.replace = jest.fn(str => str); ds.query(query as any);