-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): CfnParameter of Number type cannot be used as a string (#1…
…0422) CloudFormation allows for parameters of type 'Number' to be referenced, using the 'Ref' keyword, into properties that are of type 'String'. This will let customers now use CloudFormation maximum and minimum constraints on the number parameter type, and still use the resulting value in a property of string type. fixes #10228 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Niranjan Jayakar
authored
Sep 18, 2020
1 parent
a1df511
commit 28adc88
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Test } from 'nodeunit'; | ||
import { CfnParameter, Stack } from '../lib'; | ||
|
||
export = { | ||
'valueAsString supports both string and number types'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const numberParam = new CfnParameter(stack, 'numberParam', { type: 'Number', default: 10 }); | ||
const stringParam = new CfnParameter(stack, 'stringParam', { type: 'String', default: 'a-default' }); | ||
|
||
// WHEN | ||
const numVal = numberParam.valueAsString; | ||
const strVal = stringParam.valueAsString; | ||
|
||
// THEN | ||
test.deepEqual(stack.resolve(numVal), { Ref: 'numberParam' }); | ||
test.deepEqual(stack.resolve(strVal), { Ref: 'stringParam' }); | ||
|
||
test.done(); | ||
}, | ||
|
||
'valueAsString fails for unsupported types'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const listParam = new CfnParameter(stack, 'listParam', { type: 'List', default: 10 }); | ||
|
||
// WHEN - THEN | ||
test.throws(() => listParam.valueAsList, /Parameter type \(List\)/); | ||
|
||
test.done(); | ||
}, | ||
} |