|
|
|
|
@ -11,6 +11,8 @@ interface TestCase { |
|
|
|
|
key?: 'value' | 'text'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const suffix = 'suffix'; |
|
|
|
|
|
|
|
|
|
describe('templateVariableUtils', () => { |
|
|
|
|
const multiValuedRepresentedAsArray = { |
|
|
|
|
...logGroupNamesVariable, |
|
|
|
|
@ -70,14 +72,57 @@ describe('templateVariableUtils', () => { |
|
|
|
|
test.each(cases)('$name', async ({ variable, expected, key }) => { |
|
|
|
|
const templateService = setupMockedTemplateService([variable]); |
|
|
|
|
const strings = ['$' + variable.name, 'log-group']; |
|
|
|
|
const result = interpolateStringArrayUsingSingleOrMultiValuedVariable(templateService, strings, key); |
|
|
|
|
const result = interpolateStringArrayUsingSingleOrMultiValuedVariable(templateService, strings, {}, key); |
|
|
|
|
expect(result).toEqual([...expected, 'log-group']); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const casesWithMultipleVariablesInString: TestCase[] = [ |
|
|
|
|
{ |
|
|
|
|
name: 'string with multiple variables should expand multi-valued variable with two values and use the metric find values', |
|
|
|
|
variable: logGroupNamesVariable, |
|
|
|
|
expected: [`${regionVariable.current.text}-${[...logGroupNamesVariable.current.value].join('|')}-${suffix}`], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'string with multiple variables should expand multi-valued variable with two values and use the metric find texts', |
|
|
|
|
variable: logGroupNamesVariable, |
|
|
|
|
expected: [`${regionVariable.current.text}-${[...logGroupNamesVariable.current.text].join(' + ')}-${suffix}`], |
|
|
|
|
key: 'text', |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'string with multiple variables should expand multi-valued variable with one selected value represented as array and use metric find values', |
|
|
|
|
variable: multiValuedRepresentedAsArray, |
|
|
|
|
expected: [`${regionVariable.current.text}-${multiValuedRepresentedAsArray.current.value}-${suffix}`], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'should expand multi-valued variable with one selected value represented as array and use metric find texts', |
|
|
|
|
variable: multiValuedRepresentedAsArray, |
|
|
|
|
expected: [`${regionVariable.current.text}-${multiValuedRepresentedAsArray.current.text}-${suffix}`], |
|
|
|
|
key: 'text', |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'string with multiple variables should expand multi-valued variable with one selected value represented as a string and use metric find value', |
|
|
|
|
variable: multiValuedRepresentedAsString, |
|
|
|
|
expected: [`${regionVariable.current.text}-${multiValuedRepresentedAsString.current.value}-${suffix}`], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'string with multiple variables should expand multi-valued variable with one selected value represented as a string and use metric find text', |
|
|
|
|
variable: multiValuedRepresentedAsString, |
|
|
|
|
expected: [`${regionVariable.current.text}-${multiValuedRepresentedAsString.current.text}-${suffix}`], |
|
|
|
|
key: 'text', |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
test.each(casesWithMultipleVariablesInString)('$name', async ({ variable, expected, key }) => { |
|
|
|
|
const templateService = setupMockedTemplateService([regionVariable, variable]); |
|
|
|
|
const strings = [`$${regionVariable.name}-$${variable.name}-${suffix}`, 'log-group']; |
|
|
|
|
const result = interpolateStringArrayUsingSingleOrMultiValuedVariable(templateService, strings, {}, key); |
|
|
|
|
expect(result).toEqual([...expected, 'log-group']); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should expand single-valued variable', () => { |
|
|
|
|
const templateService = setupMockedTemplateService([regionVariable]); |
|
|
|
|
const strings = ['$' + regionVariable.name, 'us-east-2']; |
|
|
|
|
const result = interpolateStringArrayUsingSingleOrMultiValuedVariable(templateService, strings); |
|
|
|
|
const result = interpolateStringArrayUsingSingleOrMultiValuedVariable(templateService, strings, {}); |
|
|
|
|
expect(result).toEqual([regionVariable.current.value, 'us-east-2']); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|