migrateAnnotation.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { AnnotationQuery } from '@grafana/data';
  2. import { AzureMonitorQuery, AzureQueryType } from '../types';
  3. import migrateAnnotation from './migrateAnnotation';
  4. const OLD_ANNOTATION: AnnotationQuery<AzureMonitorQuery> = {
  5. datasource: null,
  6. enable: true,
  7. iconColor: 'red',
  8. name: 'azure-activity',
  9. queryType: 'Azure Log Analytics',
  10. subscription: 'abc-123-def-456',
  11. rawQuery: 'AzureActivity\r\n| where $__timeFilter() \r\n| project TimeGenerated, Text=OperationName',
  12. workspace:
  13. '/subscriptions/abc-123-def-456/resourcegroups/our-datasource/providers/microsoft.operationalinsights/workspaces/azureactivitylog',
  14. target: {
  15. refId: 'Anno',
  16. },
  17. };
  18. const NEW_ANNOTATION: AnnotationQuery<AzureMonitorQuery> = {
  19. datasource: null,
  20. enable: true,
  21. iconColor: 'red',
  22. name: 'azure-activity',
  23. rawQuery: undefined,
  24. workspace: undefined,
  25. subscription: undefined,
  26. queryType: undefined,
  27. target: {
  28. refId: 'Anno',
  29. queryType: AzureQueryType.LogAnalytics,
  30. azureLogAnalytics: {
  31. query: 'AzureActivity\r\n| where $__timeFilter() \r\n| project TimeGenerated, Text=OperationName',
  32. resource:
  33. '/subscriptions/abc-123-def-456/resourcegroups/our-datasource/providers/microsoft.operationalinsights/workspaces/azureactivitylog',
  34. },
  35. },
  36. };
  37. describe('AzureMonitor: migrateAnnotation', () => {
  38. it('migrates old annotations to AzureMonitorQuery', () => {
  39. const migrated = migrateAnnotation(OLD_ANNOTATION);
  40. expect(migrated).toEqual(NEW_ANNOTATION);
  41. });
  42. it('passes through already migrated queries untouched', () => {
  43. const newAnnotation = { ...NEW_ANNOTATION };
  44. delete newAnnotation.rawQuery;
  45. delete newAnnotation.workspace;
  46. delete newAnnotation.subscription;
  47. delete newAnnotation.queryType;
  48. const migrated = migrateAnnotation(newAnnotation);
  49. // We use .toBe because we want to assert that the object identity did not change!!!
  50. expect(migrated).toBe(newAnnotation);
  51. });
  52. });