mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Expressions: More robust expression check (#65006)
More robust expression check
This commit is contained in:
@@ -2,16 +2,21 @@ import { of } from 'rxjs';
|
||||
import { BackendSrv, BackendSrvRequest, FetchResponse } from 'src/services';
|
||||
|
||||
import {
|
||||
DataSourceJsonData,
|
||||
DataQuery,
|
||||
DataSourceInstanceSettings,
|
||||
DataQueryRequest,
|
||||
DataQueryResponseData,
|
||||
MutableDataFrame,
|
||||
DataSourceInstanceSettings,
|
||||
DataSourceJsonData,
|
||||
DataSourceRef,
|
||||
MutableDataFrame,
|
||||
} from '@grafana/data';
|
||||
|
||||
import { DataSourceWithBackend, standardStreamOptionsProvider, toStreamingDataResponse } from './DataSourceWithBackend';
|
||||
import {
|
||||
DataSourceWithBackend,
|
||||
isExpressionReference,
|
||||
standardStreamOptionsProvider,
|
||||
toStreamingDataResponse,
|
||||
} from './DataSourceWithBackend';
|
||||
|
||||
class MyDataSource extends DataSourceWithBackend<DataQuery, DataSourceJsonData> {
|
||||
constructor(instanceSettings: DataSourceInstanceSettings<DataSourceJsonData>) {
|
||||
@@ -239,6 +244,16 @@ describe('DataSourceWithBackend', () => {
|
||||
url: '/api/datasources/uid/abc/health',
|
||||
});
|
||||
});
|
||||
|
||||
describe('isExpressionReference', () => {
|
||||
test('check all possible expression references', () => {
|
||||
expect(isExpressionReference('__expr__')).toBeTruthy(); // New UID
|
||||
expect(isExpressionReference('-100')).toBeTruthy(); // Legacy UID
|
||||
expect(isExpressionReference('Expression')).toBeTruthy(); // Name
|
||||
expect(isExpressionReference({ type: '__expr__' })).toBeTruthy();
|
||||
expect(isExpressionReference({ type: '-100' })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createMockDatasource() {
|
||||
|
||||
@@ -47,7 +47,7 @@ export function isExpressionReference(ref?: DataSourceRef | string | null): bool
|
||||
return false;
|
||||
}
|
||||
const v = typeof ref === 'string' ? ref : ref.type;
|
||||
return v === ExpressionDatasourceRef.type || v === '-100'; // -100 was a legacy accident that should be removed
|
||||
return v === ExpressionDatasourceRef.type || v === ExpressionDatasourceRef.name || v === '-100'; // -100 was a legacy accident that should be removed
|
||||
}
|
||||
|
||||
export class HealthCheckError extends Error {
|
||||
|
||||
Reference in New Issue
Block a user