mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data * Move types from grafana-ui to grafana-data * Move valueFormats to grafana-data * Move utils from grafana-ui to grafana-data * Update imports in grafana-ui * revert data's tsconfig change * Update imports in grafana-runtime * Fix import paths in grafana-ui * Move rxjs to devDeps * Core import updates batch 1 * Import updates batch 2 * Imports fix batch 3 * Imports fixes batch i don't know * Fix imorts in grafana-toolkit * Fix imports after master merge
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import {
|
|
DataSourceApi,
|
|
DataQueryRequest,
|
|
DataQueryResponse,
|
|
DataSourceInstanceSettings,
|
|
DataSourcePluginMeta,
|
|
} from '@grafana/data';
|
|
|
|
export class DatasourceSrvMock {
|
|
constructor(private defaultDS: DataSourceApi, private datasources: { [name: string]: DataSourceApi }) {
|
|
//
|
|
}
|
|
|
|
get(name?: string): Promise<DataSourceApi> {
|
|
if (!name) {
|
|
return Promise.resolve(this.defaultDS);
|
|
}
|
|
const ds = this.datasources[name];
|
|
if (ds) {
|
|
return Promise.resolve(ds);
|
|
}
|
|
return Promise.reject('Unknown Datasource: ' + name);
|
|
}
|
|
}
|
|
|
|
export class MockDataSourceApi extends DataSourceApi {
|
|
result: DataQueryResponse = { data: [] };
|
|
queryResolver: Promise<DataQueryResponse>;
|
|
|
|
constructor(name?: string, result?: DataQueryResponse) {
|
|
super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings);
|
|
if (result) {
|
|
this.result = result;
|
|
}
|
|
|
|
this.meta = {} as DataSourcePluginMeta;
|
|
}
|
|
|
|
query(request: DataQueryRequest): Promise<DataQueryResponse> {
|
|
if (this.queryResolver) {
|
|
return this.queryResolver;
|
|
}
|
|
return new Promise(resolver => {
|
|
setTimeout(() => {
|
|
resolver(this.result);
|
|
});
|
|
});
|
|
}
|
|
|
|
testDatasource() {
|
|
return Promise.resolve();
|
|
}
|
|
}
|