grafana/public/app/plugins/datasource/azuremonitor/utils/migrateAnnotation.test.ts
Andreas Christou d7f7cd1e61
Schema: Initial Azure Monitor query schema (#62018)
* Initial schema

- Add types based off of current frontend

* Rename and field-level comments

* Update report and regenerate files

* Rename frontend Azure folder

- Doing this for consistency and to ensure code-generation works
- Update betterer results due to file renames

* Remove default and add back enum vals that I deleted

* Set workspace prop as optional

* Replace template variable types

* Connect frontend query types

- Keep properties optional for now to avoid major changes
- Rename AzureMetricResource
- Correctly use ResultFormat

* Add TSVeneer decorator

* Update schema

* Update type

* Update CODEOWNERS

* Fix gen-cue issue

* Fix backend test

* Fix e2e test

* Update code coverage

* Remove references to old Azure Monitor path

* Review

* Regen files
2023-02-03 16:06:54 +00:00

66 lines
1.9 KiB
TypeScript

import { AnnotationQuery } from '@grafana/data';
import { AzureMonitorQuery, AzureQueryType } from '../types';
import migrateAnnotation from './migrateAnnotation';
const OLD_ANNOTATION: AnnotationQuery<AzureMonitorQuery> = {
datasource: null,
enable: true,
iconColor: 'red',
name: 'azure-activity',
queryType: 'Azure Log Analytics',
subscription: 'abc-123-def-456',
rawQuery: 'AzureActivity\r\n| where $__timeFilter() \r\n| project TimeGenerated, Text=OperationName',
workspace:
'/subscriptions/abc-123-def-456/resourcegroups/our-datasource/providers/microsoft.operationalinsights/workspaces/azureactivitylog',
target: {
refId: 'Anno',
},
};
const NEW_ANNOTATION: AnnotationQuery<AzureMonitorQuery> = {
datasource: null,
enable: true,
iconColor: 'red',
name: 'azure-activity',
rawQuery: undefined,
workspace: undefined,
subscription: undefined,
queryType: undefined,
target: {
refId: 'Anno',
queryType: AzureQueryType.LogAnalytics,
azureLogAnalytics: {
query: 'AzureActivity\r\n| where $__timeFilter() \r\n| project TimeGenerated, Text=OperationName',
resources: [
'/subscriptions/abc-123-def-456/resourcegroups/our-datasource/providers/microsoft.operationalinsights/workspaces/azureactivitylog',
],
},
},
};
describe('AzureMonitor: migrateAnnotation', () => {
it('migrates old annotations to AzureMonitorQuery', () => {
const migrated = migrateAnnotation(OLD_ANNOTATION);
expect(migrated).toEqual(NEW_ANNOTATION);
});
it('passes through already migrated queries untouched', () => {
const newAnnotation = { ...NEW_ANNOTATION };
delete newAnnotation.rawQuery;
delete newAnnotation.workspace;
delete newAnnotation.subscription;
delete newAnnotation.queryType;
const migrated = migrateAnnotation(newAnnotation);
// We use .toBe because we want to assert that the object identity did not change!!!
expect(migrated).toBe(newAnnotation);
});
});