You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to write a CDK unit test for my StackSetStack but I keep running into issues with this no matter how I structure it.
Targeting the Parent Stack
With this setup, the test runs but the template that is synthesized is not of any interest to me as it only contains the inner workings (Lambda, CustomResource, Assets, etc.) that makes cdk-stacksets function but it doesn't contain any of the details of my MyStackSetStack that I would like to test.
it('matches the snapshot',()=>{constapp=newApp();conststack=newStack(app,'TestStack');conststackSetStack=newMyStackSetStack(stack,'MyStackSetStack',{assetBuckets: [Bucket.fromBucketName(stack,'Assets','stackset-assets-us-east-2')],assetBucketPrefix: 'stackset-assets',});consttemplate=Template.fromStack(stack);expect(template).toMatchSnapshot();});
Targeting the StackSetStack
Since StackSetStack extends Stack, I figured I could just switch Template.fromStack to target the stackSetStack directly and then I would get the template I want to run my tests against.
But with this setup, I always get this error:
Unable to find artifact with id "TestStackMyStackSetStackXXXXXXXX"
Fwiw, as a workaround I move the entirety of my template code into a separate construct, then test that as if it was put into a normal Stack.
classMyTemplateStack(StackSetStack):
def__init__(...):
super().__init__(...)
MyCustomConstruct(...)
classMyCustomConstruct(Construct):
def__init__(...):
# here is where i build all my actual resources
deftest_custom_construct():
regular_stack=Stack()
MyCustomConstruct(scope=regular_stack, ...)
template=Template.from_stack(regular_stack)
# make assertions on template like normal
I've been trying to write a CDK unit test for my
StackSetStack
but I keep running into issues with this no matter how I structure it.Targeting the Parent Stack
With this setup, the test runs but the template that is synthesized is not of any interest to me as it only contains the inner workings (Lambda, CustomResource, Assets, etc.) that makes
cdk-stacksets
function but it doesn't contain any of the details of myMyStackSetStack
that I would like to test.Targeting the StackSetStack
Since
StackSetStack
extendsStack
, I figured I could just switchTemplate.fromStack
to target thestackSetStack
directly and then I would get the template I want to run my tests against.But with this setup, I always get this error:
Unable to find artifact with id "TestStackMyStackSetStackXXXXXXXX"
Removing Parent Stack All Together
Next I tried to just remove the Parent stack entirely and just create the
MyStackSetStack
on the app itself.But this gave me this error because of the asset bucket:
App at '' should be created in the scope of a Stack, but no Stack found
Removing Asset Bucket
So my last attempt was to do it without the asset bucket but this resulted in this error:
Again, since the
StackSetStack
is aStack
, it would be nice if we could test them just like we do any other AWS CDK stack.The text was updated successfully, but these errors were encountered: