grafana/public/app/plugins/datasource/elasticsearch/mocks.ts
Matias Chomicki 5767c01a79
Elasticsearch: fix types in test and add mock factory (#54582)
* refactor(elastic-test): add datasource mock factory

* refactor(elastic-test): use new factory and attempt to fix some type issues

* refactor(elastic-test): type fixes

* refactor(elastic-test): update test with mock changes

* refactor(elastic-test): remove commented code

Git history should be more than enough to go back to previous revisions instead of keeping commented code.

* refactor(elastic-test): use mock factory and fix type issues in language provider test

* Chore: rename mock parameter

* Chore: remove unnecessary conditional

* Chore: remove ts-expect-error
2022-09-06 14:35:54 +02:00

54 lines
1.2 KiB
TypeScript

import { DataSourceInstanceSettings, PluginType } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { ElasticDatasource } from './datasource';
import { ElasticsearchOptions } from './types';
export function createElasticDatasource(
settings: Partial<DataSourceInstanceSettings<ElasticsearchOptions>> = {},
templateSrv: TemplateSrv
) {
const { jsonData, ...rest } = settings;
const instanceSettings: DataSourceInstanceSettings<ElasticsearchOptions> = {
id: 1,
meta: {
id: 'id',
name: 'name',
type: PluginType.datasource,
module: '',
baseUrl: '',
info: {
author: {
name: 'Test',
},
description: '',
links: [],
logos: {
large: '',
small: '',
},
screenshots: [],
updated: '',
version: '',
},
},
readOnly: false,
name: 'test-elastic',
type: 'type',
uid: 'uid',
access: 'proxy',
url: '',
jsonData: {
timeField: '',
esVersion: '',
timeInterval: '',
...jsonData,
},
database: '[test-]YYYY.MM.DD',
...rest,
};
return new ElasticDatasource(instanceSettings, templateSrv);
}