datasource.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { createMockInstanceSetttings } from './__mocks__/instanceSettings';
  2. import createMockQuery from './__mocks__/query';
  3. import Datasource from './datasource';
  4. describe('Azure Monitor Datasource', () => {
  5. describe('interpolateVariablesInQueries()', () => {
  6. it('should interpolate variables in the queries', () => {
  7. const ds = new Datasource(createMockInstanceSetttings());
  8. const queries = [createMockQuery({ azureMonitor: { resourceGroup: '$resourceGroup' } })];
  9. const interpolatedQueries = ds.interpolateVariablesInQueries(queries, {
  10. resourceGroup: { text: 'the-resource-group', value: 'the-resource-group' },
  11. });
  12. expect(interpolatedQueries).toContainEqual(
  13. expect.objectContaining({
  14. azureMonitor: expect.objectContaining({ resourceGroup: 'the-resource-group' }),
  15. })
  16. );
  17. });
  18. it('should include a datasource ref when interpolating queries', () => {
  19. const ds = new Datasource(createMockInstanceSetttings());
  20. const query = createMockQuery();
  21. delete query.datasource;
  22. const queries = [query];
  23. const interpolatedQueries = ds.interpolateVariablesInQueries(queries, {});
  24. expect(interpolatedQueries).toContainEqual(
  25. expect.objectContaining({
  26. datasource: expect.objectContaining({ type: 'azuremonitor', uid: 'abc' }),
  27. })
  28. );
  29. });
  30. });
  31. });