Skip to content

Commit

Permalink
refactoring suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerebrovinny committed Nov 13, 2024
1 parent 1a0d381 commit 21c59b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion internal/exec/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ func ExecuteDescribeStacks(
continue
}

stackEntry := finalStacksMap[stackName].(map[string]any)
stackEntry, ok := finalStacksMap[stackName].(map[string]any)
if !ok {
return nil, fmt.Errorf("invalid stack entry type for stack %s", stackName)
}
componentsSection, hasComponents := stackEntry["components"].(map[string]any)

if !hasComponents {
Expand Down
22 changes: 20 additions & 2 deletions pkg/describe/describe_stacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,18 @@ func TestDescribeStacksWithEmptyStacks(t *testing.T) {
foundEmptyStack := false
for _, stackContent := range stacksWithEmpty {
if components, ok := stackContent.(map[string]any)["components"].(map[string]any); ok {
if len(components) == 0 || (len(components) == 1 && len(components["terraform"].(map[string]any)) == 0) {
if len(components) == 0 {
foundEmptyStack = true
break
}
if len(components) == 1 {
if terraformComps, hasTerraform := components["terraform"].(map[string]any); hasTerraform {
if len(terraformComps) == 0 {
foundEmptyStack = true
break
}
}
}
}
}
assert.True(t, foundEmptyStack, "Should find at least one empty stack")
Expand Down Expand Up @@ -228,11 +236,21 @@ func TestDescribeStacksWithVariousEmptyStacks(t *testing.T) {
if stack, ok := stackContent.(map[string]any); ok {
if components, hasComponents := stack["components"].(map[string]any); hasComponents {
// Check for completely empty components
if len(components) == 0 || (len(components) == 1 && len(components["terraform"].(map[string]any)) == 0) {
if len(components) == 0 {
emptyStacks = append(emptyStacks, stackName)
continue
}

// Check if only terraform exists and is empty
if len(components) == 1 {
if terraformComps, hasTerraform := components["terraform"].(map[string]any); hasTerraform {
if len(terraformComps) == 0 {
emptyStacks = append(emptyStacks, stackName)
continue
}
}
}

// If we have any components at all, consider it non-empty
for _, compType := range components {
if compMap, ok := compType.(map[string]any); ok && len(compMap) > 0 {
Expand Down

0 comments on commit 21c59b8

Please sign in to comment.