mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: update language provider test
This commit is contained in:
parent
f6b6c69194
commit
22e547f625
@ -1,14 +1,17 @@
|
|||||||
import Plain from 'slate-plain-serializer';
|
import Plain from 'slate-plain-serializer';
|
||||||
|
|
||||||
import { AbstractLabelOperator } from '@grafana/data';
|
import { AbstractLabelOperator, DataFrame } from '@grafana/data';
|
||||||
import { TypeaheadInput } from '@grafana/ui';
|
import { TypeaheadInput } from '@grafana/ui';
|
||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
import { executeAnnotationQuery } from 'app/features/annotations/executeAnnotationQuery';
|
||||||
|
|
||||||
import LanguageProvider, { LokiHistoryItem } from './LanguageProvider';
|
import LanguageProvider, { LokiHistoryItem } from './LanguageProvider';
|
||||||
import { LokiDatasource } from './datasource';
|
import { LokiDatasource } from './datasource';
|
||||||
import { createLokiDatasource, createMetadataRequest } from './mocks';
|
import { createLokiDatasource, createMetadataRequest } from './mocks';
|
||||||
|
import { extractLogParserFromDataFrame } from './responseUtils';
|
||||||
import { LokiQueryType } from './types';
|
import { LokiQueryType } from './types';
|
||||||
|
|
||||||
|
jest.mock('./responseUtils');
|
||||||
|
|
||||||
jest.mock('app/store/store', () => ({
|
jest.mock('app/store/store', () => ({
|
||||||
store: {
|
store: {
|
||||||
getState: jest.fn().mockReturnValue({
|
getState: jest.fn().mockReturnValue({
|
||||||
@ -297,6 +300,49 @@ describe('Query imports', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getParserAndLabelKeys()', () => {
|
||||||
|
let datasource: LokiDatasource, languageProvider: LanguageProvider;
|
||||||
|
const extractLogParserFromDataFrameMock = extractLogParserFromDataFrame as jest.Mock;
|
||||||
|
beforeEach(() => {
|
||||||
|
datasource = createLokiDatasource();
|
||||||
|
languageProvider = new LanguageProvider(datasource);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('identifies selectors with JSON parser data', async () => {
|
||||||
|
jest.spyOn(datasource, 'getDataSamples').mockResolvedValue([{}] as DataFrame[]);
|
||||||
|
extractLogParserFromDataFrameMock.mockReturnValueOnce({ hasLogfmt: false, hasJSON: true });
|
||||||
|
|
||||||
|
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||||
|
extractedLabelKeys: [],
|
||||||
|
hasJSON: true,
|
||||||
|
hasLogfmt: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('identifies selectors with Logfmt parser data', async () => {
|
||||||
|
jest.spyOn(datasource, 'getDataSamples').mockResolvedValue([{}] as DataFrame[]);
|
||||||
|
extractLogParserFromDataFrameMock.mockReturnValueOnce({ hasLogfmt: true, hasJSON: false });
|
||||||
|
|
||||||
|
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||||
|
extractedLabelKeys: [],
|
||||||
|
hasJSON: false,
|
||||||
|
hasLogfmt: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('correctly processes empty data', async () => {
|
||||||
|
jest.spyOn(datasource, 'getDataSamples').mockResolvedValue([]);
|
||||||
|
extractLogParserFromDataFrameMock.mockClear();
|
||||||
|
|
||||||
|
expect(await languageProvider.getParserAndLabelKeys('{place="luna"}')).toEqual({
|
||||||
|
extractedLabelKeys: [],
|
||||||
|
hasJSON: false,
|
||||||
|
hasLogfmt: false,
|
||||||
|
});
|
||||||
|
expect(extractLogParserFromDataFrameMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getLanguageProvider(datasource: LokiDatasource) {
|
async function getLanguageProvider(datasource: LokiDatasource) {
|
||||||
@ -334,7 +380,7 @@ function setup(
|
|||||||
labelsAndValues: Record<string, string[]>,
|
labelsAndValues: Record<string, string[]>,
|
||||||
series?: Record<string, Array<Record<string, string>>>
|
series?: Record<string, Array<Record<string, string>>>
|
||||||
): LokiDatasource {
|
): LokiDatasource {
|
||||||
const datasource = createLokiDatasource({} as unknown as TemplateSrv);
|
const datasource = createLokiDatasource();
|
||||||
|
|
||||||
const rangeMock = {
|
const rangeMock = {
|
||||||
start: 1560153109000,
|
start: 1560153109000,
|
||||||
|
Loading…
Reference in New Issue
Block a user