Skip to content

Commit

Permalink
feat: #81 Do not display nested child stacks (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k authored Mar 7, 2023
1 parent 13b0345 commit c5ee563
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/operation/cloudformation_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (o *CloudFormationStackOperator) ListStacksFilteredByKeyword(ctx context.Co
}

for _, stackSummary := range stackSummaries {
// pass the nested child stacks
if stackSummary.RootId != nil {
continue
}

// for case-insensitive
lowerStackName := strings.ToLower(*stackSummary.StackName)
lowerKeyword := strings.ToLower(*keyword)
Expand Down
59 changes: 59 additions & 0 deletions internal/operation/cloudformation_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,65 @@ func TestCloudFormationStackOperator_ListStacksFilteredByKeyword(t *testing.T) {
},
wantErr: false,
},
{
name: "list stacks with RootId filtered by keyword successfully",
args: args{
ctx: ctx,
keyword: "TestStack",
},
prepareMockCloudFormationFn: func(m *client.MockICloudFormation) {
m.EXPECT().ListStacks(gomock.Any()).Return(
[]types.StackSummary{
{
StackName: aws.String("TestStack1"),
StackStatus: types.StackStatusCreateComplete,
RootId: aws.String("test-stack-root"),
},
{
StackName: aws.String("TestStack2"),
StackStatus: types.StackStatusCreateComplete,
},
},
nil,
)
},
want: want{
filteredStacks: []string{
"TestStack2",
},
err: nil,
},
wantErr: false,
},
{
name: "list stacks with RootId filtered by keyword and no stacks do not have RootId found successfully",
args: args{
ctx: ctx,
keyword: "TestStack",
},
prepareMockCloudFormationFn: func(m *client.MockICloudFormation) {
m.EXPECT().ListStacks(gomock.Any()).Return(
[]types.StackSummary{
{
StackName: aws.String("TestStack1"),
StackStatus: types.StackStatusCreateComplete,
RootId: aws.String("test-stack-root"),
},
{
StackName: aws.String("TestStack2"),
StackStatus: types.StackStatusCreateComplete,
RootId: aws.String("test-stack-root"),
},
},
nil,
)
},
want: want{
filteredStacks: []string{},
err: nil,
},
wantErr: false,
},
{
name: "list stacks filtered by lower keyword successfully",
args: args{
Expand Down

0 comments on commit c5ee563

Please sign in to comment.