Skip to content

Commit 51480c7

Browse files
authored
Replace test set-style map[string]bool usage with map[string]struct{} (#37257)
1 parent 9d06da4 commit 51480c7

27 files changed

Lines changed: 217 additions & 188 deletions

pkg/actionpins/actionpins_internal_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,19 @@ func TestInitWarnings_InitializesAndPreservesMap(t *testing.T) {
5353
})
5454

5555
t.Run("preserves existing warnings map", func(t *testing.T) {
56-
existing := map[string]bool{"actions/checkout@v5": true}
57-
ctx := &PinContext{Warnings: existing}
56+
existing := map[string]struct{}{"actions/checkout@v5": {}}
57+
ctx := &PinContext{Warnings: make(map[string]bool, len(existing))}
58+
for warning := range existing {
59+
ctx.Warnings[warning] = true
60+
}
5861

5962
initWarnings(ctx)
6063

6164
require.NotNil(t, ctx.Warnings, "Expected warnings map to remain initialized")
62-
assert.Equal(t, existing, ctx.Warnings, "Expected existing warnings entries to be preserved")
65+
assert.Len(t, ctx.Warnings, len(existing), "Expected existing warnings entries to be preserved")
66+
for warning := range existing {
67+
assert.True(t, ctx.Warnings[warning], "Expected warning %q to be preserved", warning)
68+
}
6369
})
6470
}
6571

pkg/cli/add_interactive_schedule_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,15 @@ func TestBuildScheduleOptions(t *testing.T) {
407407
t.Run("includes all standard frequencies", func(t *testing.T) {
408408
opts := buildScheduleOptions("daily", "daily")
409409
require.NotEmpty(t, opts, "options should not be empty")
410-
values := make(map[string]bool)
410+
values := make(map[string]struct{})
411411
for _, o := range opts {
412-
values[o.Value] = true
412+
values[o.Value] = struct{}{}
413413
}
414-
assert.True(t, values["hourly"], "hourly should be included")
415-
assert.True(t, values["3-hourly"], "3-hourly should be included")
416-
assert.True(t, values["daily"], "daily should be included")
417-
assert.True(t, values["weekly"], "weekly should be included")
418-
assert.True(t, values["monthly"], "monthly should be included")
414+
assert.Contains(t, values, "hourly", "hourly should be included")
415+
assert.Contains(t, values, "3-hourly", "3-hourly should be included")
416+
assert.Contains(t, values, "daily", "daily should be included")
417+
assert.Contains(t, values, "weekly", "weekly should be included")
418+
assert.Contains(t, values, "monthly", "monthly should be included")
419419
})
420420

421421
t.Run("custom schedule has no duplicate custom option", func(t *testing.T) {

pkg/cli/copilot_events_jsonl_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ func TestParseEventsJSONLFile(t *testing.T) {
172172
}
173173

174174
// Verify each expected tool name appears in ToolCalls
175-
toolNames := make(map[string]bool)
175+
toolNames := make(map[string]struct{})
176176
for _, tc := range metrics.ToolCalls {
177-
toolNames[tc.Name] = true
177+
toolNames[tc.Name] = struct{}{}
178178
}
179179
for _, expectedTool := range tt.wantToolCalls {
180-
assert.True(t, toolNames[expectedTool], "tool %q should be in ToolCalls", expectedTool)
180+
assert.Contains(t, toolNames, expectedTool, "tool %q should be in ToolCalls", expectedTool)
181181
}
182182
})
183183
}

pkg/cli/dependency_graph_test.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ description: Standalone workflow
123123
}
124124

125125
// Check that both importers are in the list
126-
affectedMap := make(map[string]bool)
126+
affectedMap := make(map[string]struct{})
127127
for _, w := range affected {
128-
affectedMap[w] = true
128+
affectedMap[w] = struct{}{}
129129
}
130130

131-
if !affectedMap[topWorkflow1] {
131+
if _, ok := affectedMap[topWorkflow1]; !ok {
132132
t.Errorf("GetAffectedWorkflows() should include %s", topWorkflow1)
133133
}
134-
if !affectedMap[topWorkflow2] {
134+
if _, ok := affectedMap[topWorkflow2]; !ok {
135135
t.Errorf("GetAffectedWorkflows() should include %s", topWorkflow2)
136136
}
137137
})
@@ -353,13 +353,13 @@ imports:
353353
}
354354

355355
// Verify all three workflows are in the affected list
356-
affectedMap := make(map[string]bool)
356+
affectedMap := make(map[string]struct{})
357357
for _, w := range affected {
358-
affectedMap[w] = true
358+
affectedMap[w] = struct{}{}
359359
}
360360

361361
for i, wf := range workflows {
362-
if !affectedMap[wf] {
362+
if _, ok := affectedMap[wf]; !ok {
363363
t.Errorf("GetAffectedWorkflows() should include workflow%d.md", i)
364364
}
365365
}
@@ -662,12 +662,18 @@ imports:
662662
t.Errorf("GetAffectedWorkflows(C) returned %d workflows, want 3", len(affected))
663663
}
664664

665-
affectedMap := make(map[string]bool)
665+
affectedMap := make(map[string]struct{})
666666
for _, w := range affected {
667-
affectedMap[w] = true
667+
affectedMap[w] = struct{}{}
668668
}
669669

670-
if !affectedMap[top1] || !affectedMap[top2] || !affectedMap[top3] {
670+
if _, ok := affectedMap[top1]; !ok {
671+
t.Errorf("GetAffectedWorkflows(C) should include top1, top2, and top3")
672+
}
673+
if _, ok := affectedMap[top2]; !ok {
674+
t.Errorf("GetAffectedWorkflows(C) should include top1, top2, and top3")
675+
}
676+
if _, ok := affectedMap[top3]; !ok {
671677
t.Errorf("GetAffectedWorkflows(C) should include top1, top2, and top3")
672678
}
673679
})
@@ -680,12 +686,18 @@ imports:
680686
t.Errorf("GetAffectedWorkflows(B) returned %d workflows, want 3", len(affected))
681687
}
682688

683-
affectedMap := make(map[string]bool)
689+
affectedMap := make(map[string]struct{})
684690
for _, w := range affected {
685-
affectedMap[w] = true
691+
affectedMap[w] = struct{}{}
686692
}
687693

688-
if !affectedMap[top1] || !affectedMap[top2] || !affectedMap[top3] {
694+
if _, ok := affectedMap[top1]; !ok {
695+
t.Errorf("GetAffectedWorkflows(B) should include top1, top2, and top3")
696+
}
697+
if _, ok := affectedMap[top2]; !ok {
698+
t.Errorf("GetAffectedWorkflows(B) should include top1, top2, and top3")
699+
}
700+
if _, ok := affectedMap[top3]; !ok {
689701
t.Errorf("GetAffectedWorkflows(B) should include top1, top2, and top3")
690702
}
691703
})
@@ -698,16 +710,19 @@ imports:
698710
t.Errorf("GetAffectedWorkflows(A) returned %d workflows, want 2", len(affected))
699711
}
700712

701-
affectedMap := make(map[string]bool)
713+
affectedMap := make(map[string]struct{})
702714
for _, w := range affected {
703-
affectedMap[w] = true
715+
affectedMap[w] = struct{}{}
704716
}
705717

706-
if !affectedMap[top1] || !affectedMap[top2] {
718+
if _, ok := affectedMap[top1]; !ok {
719+
t.Errorf("GetAffectedWorkflows(A) should include top1 and top2")
720+
}
721+
if _, ok := affectedMap[top2]; !ok {
707722
t.Errorf("GetAffectedWorkflows(A) should include top1 and top2")
708723
}
709724

710-
if affectedMap[top3] {
725+
if _, ok := affectedMap[top3]; ok {
711726
t.Errorf("GetAffectedWorkflows(A) should NOT include top3")
712727
}
713728
})

pkg/cli/engine_secrets.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ func getMissingRequiredSecrets(requirements []SecretRequirement, existingSecrets
174174
return missing
175175
}
176176

177+
func stringSetToBoolMap(set map[string]struct{}) map[string]bool {
178+
if len(set) == 0 {
179+
return map[string]bool{}
180+
}
181+
182+
result := make(map[string]bool, len(set))
183+
for item := range set {
184+
result[item] = true
185+
}
186+
return result
187+
}
188+
177189
// ctx returns the context from the config, defaulting to background if nil
178190
func (c EngineSecretConfig) ctx() context.Context {
179191
if c.Ctx != nil {

0 commit comments

Comments
 (0)