From 120e9044c7d8b4c3ba2acb2502de6340a480dec3 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:53:33 +0100 Subject: [PATCH] Loki: Remove getQueryOptions as not needed in tests (#80747) * Loki: Remove getQueryOptions as not needed in tests * Update to not assert --- .../datasource/loki/datasource.test.ts | 58 +++++++++++++------ .../datasource/loki/getDerivedFields.test.ts | 1 - 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/public/app/plugins/datasource/loki/datasource.test.ts b/public/app/plugins/datasource/loki/datasource.test.ts index 70702abcc71..4f37e1b0d8d 100644 --- a/public/app/plugins/datasource/loki/datasource.test.ts +++ b/public/app/plugins/datasource/loki/datasource.test.ts @@ -1,6 +1,5 @@ import { of } from 'rxjs'; import { take } from 'rxjs/operators'; -import { getQueryOptions } from 'test/helpers/getQueryOptions'; import { AbstractLabelOperator, @@ -18,6 +17,7 @@ import { toDataFrame, TimeRange, ToggleFilterAction, + DataQueryRequest, } from '@grafana/data'; import { BackendSrv, @@ -122,6 +122,17 @@ const mockTimeRange = { raw: { from: dateTime(0), to: dateTime(1) }, }; +const baseRequestOptions = { + requestId: '', + interval: '', + intervalMs: 1, + range: mockTimeRange, + scopedVars: {}, + timezone: '', + app: '', + startTime: 1, +}; + interface AdHocFilter { condition: string; key: string; @@ -160,10 +171,11 @@ describe('LokiDatasource', () => { // and applyTemplateVariables is a convenient place to do that. const spy = jest.spyOn(ds, 'applyTemplateVariables'); - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: '{a="b"}', refId: 'B', maxLines: queryMaxLines }], app: app ?? CoreApp.Dashboard, - }); + }; const fetchMock = jest.fn().mockReturnValue(of({ data: testLogsResponse })); setBackendSrv({ ...origBackendSrv, fetch: fetchMock }); @@ -1239,36 +1251,40 @@ describe('LokiDatasource', () => { }); it('creates provider for logs query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: '{label="value"}', refId: 'A', queryType: LokiQueryType.Range }], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined(); }); it('does not create provider for metrics query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: 'rate({label="value"}[1m])', refId: 'A' }], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined(); }); it('creates provider if at least one query is a logs query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [ { expr: 'rate({label="value"}[1m])', queryType: LokiQueryType.Range, refId: 'A' }, { expr: '{label="value"}', queryType: LokiQueryType.Range, refId: 'B' }, ], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined(); }); it('does not create provider if there is only an instant logs query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: '{label="value"', refId: 'A', queryType: LokiQueryType.Instant }], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined(); }); @@ -1281,28 +1297,31 @@ describe('LokiDatasource', () => { }); it('creates provider for metrics query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: 'rate({label="value"}[5m])', refId: 'A' }], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined(); }); it('does not create provider for log query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [{ expr: '{label="value"}', refId: 'A' }], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).not.toBeDefined(); }); it('creates provider if at least one query is a metric query', () => { - const options = getQueryOptions({ + const options: DataQueryRequest = { + ...baseRequestOptions, targets: [ { expr: 'rate({label="value"}[1m])', refId: 'A' }, { expr: '{label="value"}', refId: 'B' }, ], - }); + }; expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined(); }); @@ -1551,10 +1570,11 @@ describe('LokiDatasource', () => { ], ])('supports query splitting when the requirements are met', async (targets: LokiQuery[]) => { const ds = createLokiDatasource(templateSrvStub); - const query = getQueryOptions({ + const query: DataQueryRequest = { + ...baseRequestOptions, targets, app: CoreApp.Dashboard, - }); + }; await expect(ds.query(query)).toEmitValuesWith(() => { expect(runSplitQuery).toHaveBeenCalled(); diff --git a/public/app/plugins/datasource/loki/getDerivedFields.test.ts b/public/app/plugins/datasource/loki/getDerivedFields.test.ts index f5d13c339f1..41004b16c1f 100644 --- a/public/app/plugins/datasource/loki/getDerivedFields.test.ts +++ b/public/app/plugins/datasource/loki/getDerivedFields.test.ts @@ -3,7 +3,6 @@ import { createDataFrame } from '@grafana/data'; import { getDerivedFields } from './getDerivedFields'; jest.mock('@grafana/runtime', () => ({ - // @ts-ignore ...jest.requireActual('@grafana/runtime'), getDataSourceSrv: () => { return {