Skip to content

Commit fcf3e3e

Browse files
[autofix.ci] apply automated fixes
1 parent 8c91961 commit fcf3e3e

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

internal/exec/describe_stacks_component_processor.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,17 @@ func stackHasNonEmptyComponents(componentsSection map[string]any) bool {
810810
// if description is non-empty and the sections filter allows it.
811811
// The first non-empty description found wins (idempotent: existing values are not overwritten).
812812
func setStackDescription(finalStacksMap map[string]any, stackName string, description string, sections []string) {
813-
if len(sections) > 0 && !u.SliceContainsString(sections, cfg.DescriptionSectionName) {
814-
return
815-
}
816-
if description == "" {
817-
return
818-
}
819-
stackEntry, ok := finalStacksMap[stackName].(map[string]any)
820-
if !ok {
821-
return
822-
}
823-
if _, exists := stackEntry[cfg.DescriptionSectionName]; !exists {
824-
stackEntry[cfg.DescriptionSectionName] = description
825-
}
813+
if len(sections) > 0 && !u.SliceContainsString(sections, cfg.DescriptionSectionName) {
814+
return
815+
}
816+
if description == "" {
817+
return
818+
}
819+
stackEntry, ok := finalStacksMap[stackName].(map[string]any)
820+
if !ok {
821+
return
822+
}
823+
if _, exists := stackEntry[cfg.DescriptionSectionName]; !exists {
824+
stackEntry[cfg.DescriptionSectionName] = description
825+
}
826826
}

internal/exec/describe_stacks_test.go

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -750,63 +750,63 @@ func TestProcessStackFile_NoGhostEntry_FilterByStack(t *testing.T) {
750750

751751
// TestSetStackDescription covers all branches of the setStackDescription helper.
752752
func TestSetStackDescription(t *testing.T) {
753-
t.Run("sections filter excludes description – no-op", func(t *testing.T) {
754-
finalMap := map[string]any{
755-
"my-stack": map[string]any{},
756-
}
757-
// sections is non-empty but does not include "description", so the early return should fire.
758-
setStackDescription(finalMap, "my-stack", "some description", []string{"vars"})
759-
stackEntry := finalMap["my-stack"].(map[string]any)
760-
_, exists := stackEntry[cfg.DescriptionSectionName]
761-
assert.False(t, exists, "description should not be set when it is absent from the sections filter")
762-
})
763-
764-
t.Run("empty description – no-op", func(t *testing.T) {
765-
finalMap := map[string]any{
766-
"my-stack": map[string]any{},
767-
}
768-
setStackDescription(finalMap, "my-stack", "", nil)
769-
stackEntry := finalMap["my-stack"].(map[string]any)
770-
_, exists := stackEntry[cfg.DescriptionSectionName]
771-
assert.False(t, exists, "description should not be set when value is empty string")
772-
})
773-
774-
t.Run("finalStacksMap entry not a map – no-op", func(t *testing.T) {
775-
finalMap := map[string]any{
776-
"my-stack": "not-a-map",
777-
}
778-
// Should not panic; the non-map stack entry triggers the guard and returns.
779-
setStackDescription(finalMap, "my-stack", "some description", nil)
780-
// Entry remains unchanged.
781-
assert.Equal(t, "not-a-map", finalMap["my-stack"])
782-
})
783-
784-
t.Run("description set on first call", func(t *testing.T) {
785-
finalMap := map[string]any{
786-
"my-stack": map[string]any{},
787-
}
788-
setStackDescription(finalMap, "my-stack", "hello world", nil)
789-
stackEntry := finalMap["my-stack"].(map[string]any)
790-
assert.Equal(t, "hello world", stackEntry[cfg.DescriptionSectionName])
791-
})
792-
793-
t.Run("idempotent – second call does not overwrite", func(t *testing.T) {
794-
finalMap := map[string]any{
795-
"my-stack": map[string]any{
796-
cfg.DescriptionSectionName: "original",
797-
},
798-
}
799-
setStackDescription(finalMap, "my-stack", "overwrite-attempt", nil)
800-
stackEntry := finalMap["my-stack"].(map[string]any)
801-
assert.Equal(t, "original", stackEntry[cfg.DescriptionSectionName], "existing description should not be overwritten")
802-
})
803-
804-
t.Run("sections filter includes description – description is set", func(t *testing.T) {
805-
finalMap := map[string]any{
806-
"my-stack": map[string]any{},
807-
}
808-
setStackDescription(finalMap, "my-stack", "filtered in", []string{cfg.DescriptionSectionName})
809-
stackEntry := finalMap["my-stack"].(map[string]any)
810-
assert.Equal(t, "filtered in", stackEntry[cfg.DescriptionSectionName])
811-
})
753+
t.Run("sections filter excludes description – no-op", func(t *testing.T) {
754+
finalMap := map[string]any{
755+
"my-stack": map[string]any{},
756+
}
757+
// sections is non-empty but does not include "description", so the early return should fire.
758+
setStackDescription(finalMap, "my-stack", "some description", []string{"vars"})
759+
stackEntry := finalMap["my-stack"].(map[string]any)
760+
_, exists := stackEntry[cfg.DescriptionSectionName]
761+
assert.False(t, exists, "description should not be set when it is absent from the sections filter")
762+
})
763+
764+
t.Run("empty description – no-op", func(t *testing.T) {
765+
finalMap := map[string]any{
766+
"my-stack": map[string]any{},
767+
}
768+
setStackDescription(finalMap, "my-stack", "", nil)
769+
stackEntry := finalMap["my-stack"].(map[string]any)
770+
_, exists := stackEntry[cfg.DescriptionSectionName]
771+
assert.False(t, exists, "description should not be set when value is empty string")
772+
})
773+
774+
t.Run("finalStacksMap entry not a map – no-op", func(t *testing.T) {
775+
finalMap := map[string]any{
776+
"my-stack": "not-a-map",
777+
}
778+
// Should not panic; the non-map stack entry triggers the guard and returns.
779+
setStackDescription(finalMap, "my-stack", "some description", nil)
780+
// Entry remains unchanged.
781+
assert.Equal(t, "not-a-map", finalMap["my-stack"])
782+
})
783+
784+
t.Run("description set on first call", func(t *testing.T) {
785+
finalMap := map[string]any{
786+
"my-stack": map[string]any{},
787+
}
788+
setStackDescription(finalMap, "my-stack", "hello world", nil)
789+
stackEntry := finalMap["my-stack"].(map[string]any)
790+
assert.Equal(t, "hello world", stackEntry[cfg.DescriptionSectionName])
791+
})
792+
793+
t.Run("idempotent – second call does not overwrite", func(t *testing.T) {
794+
finalMap := map[string]any{
795+
"my-stack": map[string]any{
796+
cfg.DescriptionSectionName: "original",
797+
},
798+
}
799+
setStackDescription(finalMap, "my-stack", "overwrite-attempt", nil)
800+
stackEntry := finalMap["my-stack"].(map[string]any)
801+
assert.Equal(t, "original", stackEntry[cfg.DescriptionSectionName], "existing description should not be overwritten")
802+
})
803+
804+
t.Run("sections filter includes description – description is set", func(t *testing.T) {
805+
finalMap := map[string]any{
806+
"my-stack": map[string]any{},
807+
}
808+
setStackDescription(finalMap, "my-stack", "filtered in", []string{cfg.DescriptionSectionName})
809+
stackEntry := finalMap["my-stack"].(map[string]any)
810+
assert.Equal(t, "filtered in", stackEntry[cfg.DescriptionSectionName])
811+
})
812812
}

0 commit comments

Comments
 (0)