Azure Monitor: fixes undefined is not iterable (#25586)

* Azure Monitor: fixes undefined is not iterable

* Update public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/response_parser.test.ts

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* Update public/app/plugins/datasource/grafana-azure-monitor-datasource/azure_log_analytics/response_parser.test.ts

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
(cherry picked from commit c0139b7d42)
This commit is contained in:
Hugo Häggmark
2020-06-25 08:45:15 +02:00
committed by Dominik Prokop
parent b58f7741b5
commit 69e989ea9d
2 changed files with 44 additions and 5 deletions
@@ -0,0 +1,37 @@
import ResponseParser from './response_parser';
import { expect } from '../../../../../test/lib/common';
describe('createSchemaFunctions', () => {
describe('when called and results have functions', () => {
it('then it should return correct result', () => {
const functions = [
{ name: 'some name', body: 'some body', displayName: 'some displayName', category: 'some category' },
];
const parser = new ResponseParser({ functions });
const results = parser.createSchemaFunctions();
expect(results).toEqual({
['some name']: {
Body: 'some body',
DocString: 'some displayName',
Folder: 'some category',
FunctionKind: 'Unknown',
InputParameters: [],
Name: 'some name',
OutputColumns: [],
},
});
});
});
describe('when called and results have no functions', () => {
it('then it should return an empty object', () => {
const parser = new ResponseParser({});
const results = parser.createSchemaFunctions();
expect(results).toEqual({});
});
});
});
@@ -1,15 +1,14 @@
import _ from 'lodash';
import { dateTime } from '@grafana/data';
import { AnnotationEvent, dateTime, TimeSeries } from '@grafana/data';
import {
AzureLogsVariable,
AzureLogsTableData,
AzureLogsVariable,
KustoColumn,
KustoDatabase,
KustoFunction,
KustoTable,
KustoSchema,
KustoColumn,
KustoTable,
} from '../types';
import { TimeSeries, AnnotationEvent } from '@grafana/data';
export default class ResponseParser {
columns: string[];
@@ -190,6 +189,9 @@ export default class ResponseParser {
createSchemaFunctions(): { [key: string]: KustoFunction } {
const functions: { [key: string]: KustoFunction } = {};
if (!this.results.functions) {
return functions;
}
for (const func of this.results.functions) {
functions[func.name] = {