Files
grafana/public/app/plugins/datasource/influxdb/datasource_sql.test.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

import { lastValueFrom } from 'rxjs';
import config from 'app/core/config';
import { SQLQuery } from '../../../features/plugins/sql';
import InfluxDatasource from './datasource';
import {
getMockDSInstanceSettings,
mockBackendService,
mockInfluxQueryRequest,
mockInfluxSQLFetchResponse,
mockTemplateSrv,
} from './mocks';
import { InfluxVersion } from './types';
config.featureToggles.influxdbBackendMigration = true;
mockBackendService(mockInfluxSQLFetchResponse);
describe('InfluxDB SQL Support', () => {
const replaceMock = jest.fn();
const templateSrv = mockTemplateSrv(jest.fn(), replaceMock);
let sqlQuery: SQLQuery;
beforeEach(() => {
sqlQuery = {
refId: 'x',
rawSql:
'SELECT "$interpolationVar2", time FROM iox.$interpolationVar WHERE time >= $__timeFrom AND time <= $__timeTo',
};
});
describe('interpolate variables', () => {
const ds = new InfluxDatasource(getMockDSInstanceSettings({ version: InfluxVersion.SQL }), templateSrv);
it('should call replace template variables for rawSql', async () => {
await lastValueFrom(ds.query(mockInfluxQueryRequest([sqlQuery])));
expect(replaceMock.mock.calls[1][0]).toBe(
`SELECT "$interpolationVar2", time FROM iox.$interpolationVar WHERE time >= $__timeFrom AND time <= $__timeTo`
);
});
});
});