mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
sql: remove grafana-core import (#75558)
* sql: remove initialCustomVariableModelState * added fix for mysql too * linter fixes
This commit is contained in:
parent
1c57217f66
commit
8dafc28988
@ -1,10 +1,10 @@
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { CustomVariableModel, LoadingState, VariableHide } from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import { SQLExpression } from '../types';
|
||||
import { makeVariable } from '../utils/testHelpers';
|
||||
|
||||
import { DatasetSelector } from './DatasetSelector';
|
||||
import { buildMockDatasetSelectorProps, buildMockTableSelectorProps } from './SqlComponents.testHelpers';
|
||||
@ -69,34 +69,13 @@ describe('TableSelector', () => {
|
||||
});
|
||||
|
||||
describe('SQLWhereRow', () => {
|
||||
function makeVariable(id: string, name: string, multi: boolean): CustomVariableModel {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
multi,
|
||||
type: 'custom',
|
||||
includeAll: false,
|
||||
current: {},
|
||||
options: [],
|
||||
query: '',
|
||||
rootStateKey: null,
|
||||
global: false,
|
||||
hide: VariableHide.dontHide,
|
||||
skipUrlSync: false,
|
||||
index: -1,
|
||||
state: LoadingState.NotStarted,
|
||||
error: null,
|
||||
description: null,
|
||||
};
|
||||
}
|
||||
|
||||
it('should remove quotes in a where clause including multi-value variable', () => {
|
||||
const exp: SQLExpression = {
|
||||
whereString: "hostname IN ('${multiHost}')",
|
||||
};
|
||||
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', true);
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', false);
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', { multi: true });
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', { multi: false });
|
||||
|
||||
const variables = [multiVar, nonMultiVar];
|
||||
|
||||
@ -110,8 +89,8 @@ describe('SQLWhereRow', () => {
|
||||
whereString: "hostname IN ('${host}')",
|
||||
};
|
||||
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', true);
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', false);
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', { multi: true });
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', { multi: false });
|
||||
|
||||
const variables = [multiVar, nonMultiVar];
|
||||
|
||||
@ -125,8 +104,8 @@ describe('SQLWhereRow', () => {
|
||||
whereString: "hostname IN ('${nonMultiHost}')",
|
||||
};
|
||||
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', true);
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', false);
|
||||
const multiVar = makeVariable('multiVar', 'multiHost', { multi: true });
|
||||
const nonMultiVar = makeVariable('nonMultiVar', 'host', { multi: false });
|
||||
|
||||
const variables = [multiVar, nonMultiVar];
|
||||
|
||||
|
23
public/app/features/plugins/sql/utils/testHelpers.ts
Normal file
23
public/app/features/plugins/sql/utils/testHelpers.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { CustomVariableModel, LoadingState, VariableHide } from '@grafana/data';
|
||||
|
||||
export function makeVariable(id: string, name: string, attributes?: Partial<CustomVariableModel>): CustomVariableModel {
|
||||
return {
|
||||
multi: false,
|
||||
type: 'custom',
|
||||
includeAll: false,
|
||||
current: {},
|
||||
options: [],
|
||||
query: '',
|
||||
rootStateKey: null,
|
||||
global: false,
|
||||
hide: VariableHide.dontHide,
|
||||
skipUrlSync: false,
|
||||
index: -1,
|
||||
state: LoadingState.NotStarted,
|
||||
error: null,
|
||||
description: null,
|
||||
...attributes,
|
||||
id,
|
||||
name,
|
||||
};
|
||||
}
|
@ -12,8 +12,8 @@ import {
|
||||
import { FetchResponse, setBackendSrv } from '@grafana/runtime';
|
||||
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
|
||||
import { SQLQuery } from 'app/features/plugins/sql/types';
|
||||
import { makeVariable } from 'app/features/plugins/sql/utils/testHelpers';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { initialCustomVariableModelState } from 'app/features/variables/custom/reducer';
|
||||
|
||||
import { MySqlDatasource } from '../MySqlDatasource';
|
||||
import { MySQLOptions } from '../types';
|
||||
@ -30,7 +30,7 @@ describe('MySQLDatasource', () => {
|
||||
},
|
||||
} as unknown as DataSourceInstanceSettings<MySQLOptions>;
|
||||
const templateSrv: TemplateSrv = new TemplateSrv();
|
||||
const variable = { ...initialCustomVariableModelState };
|
||||
const variable = makeVariable('id1', 'name1');
|
||||
fetchMock.mockImplementation((options) => of(createFetchResponse(response)));
|
||||
|
||||
const ds = new MySqlDatasource(instanceSettings);
|
||||
|
@ -15,10 +15,9 @@ import {
|
||||
import { FetchResponse } from '@grafana/runtime';
|
||||
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
|
||||
import { QueryFormat, SQLQuery } from 'app/features/plugins/sql/types';
|
||||
import { makeVariable } from 'app/features/plugins/sql/utils/testHelpers';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
import { initialCustomVariableModelState } from '../../../features/variables/custom/reducer';
|
||||
|
||||
import { PostgresDatasource } from './datasource';
|
||||
import { PostgresOptions } from './types';
|
||||
|
||||
@ -50,7 +49,7 @@ describe('PostgreSQLDatasource', () => {
|
||||
},
|
||||
} as unknown as DataSourceInstanceSettings<PostgresOptions>;
|
||||
const templateSrv: TemplateSrv = new TemplateSrv();
|
||||
const variable = { ...initialCustomVariableModelState };
|
||||
const variable = makeVariable('id1', 'name1');
|
||||
const ds = new PostgresDatasource(instanceSettings);
|
||||
Reflect.set(ds, 'templateSrv', templateSrv);
|
||||
return { ds, templateSrv, variable };
|
||||
|
Loading…
Reference in New Issue
Block a user