grafana/public/app/plugins/datasource/loki/mocks.ts
kay delaney 601853fc84 Chore: Update Slate to 0.47.8 (#18412)
* Chore: Update Slate to 0.47.8
Closes #17430

* Add slate and immutable to grafana-ui deps

* Fixes some small regressions introduced

* Fix suggestions for multiple query fields

* Pin upgraded dependencies

* Prettier fix

* Remove original slate-react dependency

* Fix tiny-invariant dep

* (Temporarily) comments out source maps for grafana-ui
2019-09-17 13:16:24 +02:00

28 lines
736 B
TypeScript

import LokiDatasource from './datasource';
export function makeMockLokiDatasource(labelsAndValues: { [label: string]: string[] }): LokiDatasource {
const labels = Object.keys(labelsAndValues);
return {
metadataRequest: (url: string) => {
let responseData;
if (url === '/api/prom/label') {
responseData = labels;
} else {
const match = url.match(/^\/api\/prom\/label\/(\w*)\/values/);
if (match) {
responseData = labelsAndValues[match[1]];
}
}
if (responseData) {
return {
data: {
data: responseData,
},
};
} else {
throw new Error(`Unexpected url error, ${url}`);
}
},
} as any;
}