|
|
@ -1,4 +1,4 @@ |
|
|
|
import { setupMockedDataSource } from './__mocks__/CloudWatchDataSource'; |
|
|
|
import { dimensionVariable, labelsVariable, setupMockedDataSource } from './__mocks__/CloudWatchDataSource'; |
|
|
|
import { VariableQuery, VariableQueryType } from './types'; |
|
|
|
import { VariableQuery, VariableQueryType } from './types'; |
|
|
|
import { CloudWatchVariableSupport } from './variables'; |
|
|
|
import { CloudWatchVariableSupport } from './variables'; |
|
|
|
|
|
|
|
|
|
|
@ -16,7 +16,7 @@ const defaultQuery: VariableQuery = { |
|
|
|
refId: '', |
|
|
|
refId: '', |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const ds = setupMockedDataSource(); |
|
|
|
const ds = setupMockedDataSource({ variables: [labelsVariable, dimensionVariable] }); |
|
|
|
ds.datasource.getRegions = jest.fn().mockResolvedValue([{ label: 'a', value: 'a' }]); |
|
|
|
ds.datasource.getRegions = jest.fn().mockResolvedValue([{ label: 'a', value: 'a' }]); |
|
|
|
ds.datasource.getNamespaces = jest.fn().mockResolvedValue([{ label: 'b', value: 'b' }]); |
|
|
|
ds.datasource.getNamespaces = jest.fn().mockResolvedValue([{ label: 'b', value: 'b' }]); |
|
|
|
ds.datasource.getMetrics = jest.fn().mockResolvedValue([{ label: 'c', value: 'c' }]); |
|
|
|
ds.datasource.getMetrics = jest.fn().mockResolvedValue([{ label: 'c', value: 'c' }]); |
|
|
@ -26,7 +26,7 @@ const getEbsVolumeIds = jest.fn().mockResolvedValue([{ label: 'f', value: 'f' }] |
|
|
|
const getEc2InstanceAttribute = jest.fn().mockResolvedValue([{ label: 'g', value: 'g' }]); |
|
|
|
const getEc2InstanceAttribute = jest.fn().mockResolvedValue([{ label: 'g', value: 'g' }]); |
|
|
|
const getResourceARNs = jest.fn().mockResolvedValue([{ label: 'h', value: 'h' }]); |
|
|
|
const getResourceARNs = jest.fn().mockResolvedValue([{ label: 'h', value: 'h' }]); |
|
|
|
|
|
|
|
|
|
|
|
const variables = new CloudWatchVariableSupport(ds.datasource); |
|
|
|
const variables = new CloudWatchVariableSupport(ds.datasource, ds.templateService); |
|
|
|
|
|
|
|
|
|
|
|
describe('variables', () => { |
|
|
|
describe('variables', () => { |
|
|
|
it('should run regions', async () => { |
|
|
|
it('should run regions', async () => { |
|
|
@ -114,7 +114,7 @@ describe('variables', () => { |
|
|
|
...defaultQuery, |
|
|
|
...defaultQuery, |
|
|
|
queryType: VariableQueryType.EC2InstanceAttributes, |
|
|
|
queryType: VariableQueryType.EC2InstanceAttributes, |
|
|
|
attributeName: 'abc', |
|
|
|
attributeName: 'abc', |
|
|
|
ec2Filters: '{"a":["b"]}', |
|
|
|
ec2Filters: '{"$dimension":["b"]}', |
|
|
|
}; |
|
|
|
}; |
|
|
|
beforeEach(() => { |
|
|
|
beforeEach(() => { |
|
|
|
ds.datasource.getEc2InstanceAttribute = getEc2InstanceAttribute; |
|
|
|
ds.datasource.getEc2InstanceAttribute = getEc2InstanceAttribute; |
|
|
@ -129,7 +129,7 @@ describe('variables', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('should run if instance id set', async () => { |
|
|
|
it('should run if instance id set', async () => { |
|
|
|
const result = await variables.execute(query); |
|
|
|
const result = await variables.execute(query); |
|
|
|
expect(getEc2InstanceAttribute).toBeCalledWith(query.region, query.attributeName, { a: ['b'] }); |
|
|
|
expect(getEc2InstanceAttribute).toBeCalledWith(query.region, query.attributeName, { env: ['b'] }); |
|
|
|
expect(result).toEqual([{ text: 'g', value: 'g', expandable: true }]); |
|
|
|
expect(result).toEqual([{ text: 'g', value: 'g', expandable: true }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -139,7 +139,7 @@ describe('variables', () => { |
|
|
|
...defaultQuery, |
|
|
|
...defaultQuery, |
|
|
|
queryType: VariableQueryType.ResourceArns, |
|
|
|
queryType: VariableQueryType.ResourceArns, |
|
|
|
resourceType: 'abc', |
|
|
|
resourceType: 'abc', |
|
|
|
tags: '{"a":["b"]}', |
|
|
|
tags: '{"a":${labels:json}}', |
|
|
|
}; |
|
|
|
}; |
|
|
|
beforeEach(() => { |
|
|
|
beforeEach(() => { |
|
|
|
ds.datasource.getResourceARNs = getResourceARNs; |
|
|
|
ds.datasource.getResourceARNs = getResourceARNs; |
|
|
@ -154,7 +154,7 @@ describe('variables', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('should run if instance id set', async () => { |
|
|
|
it('should run if instance id set', async () => { |
|
|
|
const result = await variables.execute(query); |
|
|
|
const result = await variables.execute(query); |
|
|
|
expect(getResourceARNs).toBeCalledWith(query.region, query.resourceType, { a: ['b'] }); |
|
|
|
expect(getResourceARNs).toBeCalledWith(query.region, query.resourceType, { a: ['InstanceId', 'InstanceType'] }); |
|
|
|
expect(result).toEqual([{ text: 'h', value: 'h', expandable: true }]); |
|
|
|
expect(result).toEqual([{ text: 'h', value: 'h', expandable: true }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|