mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Refactor: split PanelQueryRunner into runner and state (#16685)
* check for running * split out panel state * adding test file * remove bad test
This commit is contained in:
40
public/test/mocks/datasource_srv.ts
Normal file
40
public/test/mocks/datasource_srv.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { DataSourceApi, DataQueryRequest, DataQueryResponse } from '@grafana/ui';
|
||||
|
||||
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 implements DataSourceApi {
|
||||
name: string;
|
||||
|
||||
result: DataQueryResponse = { data: [] };
|
||||
queryResolver: Promise<DataQueryResponse>;
|
||||
|
||||
constructor(DataQueryResponse, name?: string) {
|
||||
this.name = name ? name : 'MockDataSourceApi';
|
||||
}
|
||||
|
||||
query(request: DataQueryRequest): Promise<DataQueryResponse> {
|
||||
if (this.queryResolver) {
|
||||
return this.queryResolver;
|
||||
}
|
||||
return Promise.resolve(this.result);
|
||||
}
|
||||
|
||||
testDatasource() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user