Skip to content

Commit 7e97659

Browse files
committed
Add edge case test for invalid map key types
Test that value groups properly reject non-string map keys (using int as example) with the expected error message from dig validation.
1 parent 68678a5 commit 7e97659

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

map_groups_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,28 @@ func TestMapValueGroupsEdgeCases(t *testing.T) {
444444
require.Error(t, err)
445445
assert.Contains(t, err.Error(), "every entry in a map value groups must have a name")
446446
})
447+
448+
t.Run("invalid map key types should fail", func(t *testing.T) {
449+
t.Parallel()
450+
451+
type InvalidKeyParams struct {
452+
fx.In
453+
Services map[int]testSimpleService `group:"services"`
454+
}
455+
456+
var params InvalidKeyParams
457+
app := NewForTest(t,
458+
fx.Provide(
459+
fx.Annotate(
460+
func() testSimpleService { return &testBasicService{name: "test"} },
461+
fx.ResultTags(`name:"test" group:"services"`),
462+
),
463+
),
464+
fx.Populate(&params),
465+
)
466+
467+
err := app.Err()
468+
require.Error(t, err)
469+
assert.Contains(t, err.Error(), "value groups may be consumed as slices or string-keyed maps only")
470+
})
447471
}

0 commit comments

Comments
 (0)