Add IStackProps overloads to CdkTestHelper for custom stack configurations#3
Merged
Merged
Conversation
…tions
## Summary
- Added overload methods to support custom IStackProps implementations
- Enhanced testing flexibility for real-world scenarios with custom stack properties
- Added comprehensive test coverage for new overload methods
## Changes Made
### ✨ New Features
- **CdkTestHelper.CreateTestStack(string, IStackProps)**: Creates test stack with custom props
- **CdkTestHelper.CreateTestStackMinimal(string, IStackProps)**: Creates minimal test stack with custom props
### 🧪 Test Coverage
- Added tests for custom environment settings (account, region)
- Added tests for custom tags and descriptions
- Added real-world integration test simulating LightsaberStackProps usage pattern
## Benefits
- **Flexible Stack Configuration**: Supports any IStackProps implementation
- **Real-World Usage**: Enables testing with custom stack props like LightsaberStackProps
- **Maintains Simplicity**: Reduces boilerplate while supporting complex scenarios
- **Backward Compatible**: Existing code continues to work unchanged
## Usage Example
```csharp
var customProps = new LightsaberStackProps
{
Env = env,
Context = context,
Tags = tags
};
var stack = CdkTestHelper.CreateTestStackMinimal("test-stack", customProps);
var template = Template.FromStack(stack);
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
Enhances CdkTestHelper by adding overloads that accept custom IStackProps, enabling flexible testing with real-world CDK stack configurations, and adds comprehensive tests for these new methods.
- Introduces
CreateTestStack(string, IStackProps)andCreateTestStackMinimal(string, IStackProps)overloads. - Adds three new test cases verifying custom environment, tags, description, and end-to-end workflow.
- Maintains backward compatibility and reduces boilerplate for stack creation in tests.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/LayeredCraft.Cdk.Constructs.Tests/Testing/TestingHelpersTests.cs | Added tests for custom stack props overloads and real-world integration scenario |
| src/LayeredCraft.Cdk.Constructs/Testing/CdkTestHelper.cs | Added CreateTestStack and CreateTestStackMinimal overloads with XML docs |
Comments suppressed due to low confidence (3)
test/LayeredCraft.Cdk.Constructs.Tests/Testing/TestingHelpersTests.cs:229
- Consider adding assertions to verify that the custom tags passed via
stackProps.Tagsare applied to the stack (e.g., Environment and Project tags).
stack.Region.Should().Be("eu-west-1");
test/LayeredCraft.Cdk.Constructs.Tests/Testing/TestingHelpersTests.cs:250
- Add an assertion to verify that
stack.Descriptionmatches the provided customDescriptioninstackProps.
stack.Region.Should().Be("ap-southeast-2");
test/LayeredCraft.Cdk.Constructs.Tests/Testing/TestingHelpersTests.cs:280
- Add assertions to verify that the custom tags and
DescriptionfromcustomPropsare applied on the stack before creating constructs.
stack.Region.Should().Be("us-west-2");
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enhanced
CdkTestHelperwith overload methods that accept customIStackPropsimplementations, enabling flexible testing scenarios for real-world CDK stacks with custom properties.Changes Made
✨ New Overload Methods
CdkTestHelper.CreateTestStack(string stackName, IStackProps stackProps)CdkTestHelper.CreateTestStackMinimal(string stackName, IStackProps stackProps)🧪 Comprehensive Test Coverage
Added three new test methods:
CdkTestHelper_ShouldCreateStackWithCustomStackPropsCdkTestHelper_ShouldCreateMinimalStackWithCustomStackPropsCdkTestHelper_ShouldWorkWithRealWorldCustomStackPropsLightsaberStackProps)Real-World Usage
This enhancement directly addresses the need to test CDK stacks with custom properties:
Benefits
✅ Flexible Configuration: Supports any
IStackPropsimplementation✅ Real-World Ready: Works with custom stack props like
LightsaberStackProps✅ Reduces Boilerplate: Eliminates manual app creation while supporting complex scenarios
✅ Backward Compatible: All existing code continues to work unchanged
✅ Well Tested: Comprehensive test coverage including integration scenarios
Test Plan
IStackProps🤖 Generated with Claude Code