diff --git a/config/config.go b/config/config.go index 5d1311a9..b044d921 100644 --- a/config/config.go +++ b/config/config.go @@ -517,7 +517,7 @@ func (c *Config) HasProfileGroup(groupKey string) bool { if err := c.loadGroups(); err != nil { return false } - _, ok := c.cached.groups[groupKey] + _, ok := c.lookupGroup(groupKey) return ok } @@ -527,13 +527,24 @@ func (c *Config) GetProfileGroup(groupKey string) (*Group, error) { return nil, err } - group, ok := c.cached.groups[groupKey] + group, ok := c.lookupGroup(groupKey) if !ok { return nil, ErrNotFound } return group, nil } +// lookupGroup finds a loaded group by name. The configuration keys are +// stored in lower case, so a group declared as "W1" is found with "W1" too, +// like profiles are. +func (c *Config) lookupGroup(groupKey string) (*Group, bool) { + if group, ok := c.cached.groups[groupKey]; ok { + return group, true + } + group, ok := c.cached.groups[strings.ToLower(groupKey)] + return group, ok +} + // GetProfileGroups returns all groups from the configuration // // If the groups section does not exist, it returns an empty map diff --git a/config/config_group_test.go b/config/config_group_test.go index f0f4d126..6d9769e8 100644 --- a/config/config_group_test.go +++ b/config/config_group_test.go @@ -223,3 +223,40 @@ groups: }) } } + +func TestGetProfileGroupMixedCase(t *testing.T) { + testData := []testGroupData{ + { + FormatTOML, + ` +[groups] +W1 = ["Dom", "Ha"] +`, + }, + { + FormatYAML, + ` +version: 2 +groups: + W1: + profiles: [Dom, Ha] +`, + }, + } + + for _, testItem := range testData { + t.Run(testItem.format, func(t *testing.T) { + c, err := Load(bytes.NewBufferString(testItem.config), testItem.format) + require.NoError(t, err) + + for _, name := range []string{"W1", "w1"} { + assert.True(t, c.HasProfileGroup(name), name) + + group, err := c.GetProfileGroup(name) + require.NoError(t, err, name) + assert.Equal(t, []string{"Dom", "Ha"}, group.Profiles) + } + assert.False(t, c.HasProfileGroup("W2")) + }) + } +}