Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions config/config_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
}
}
Loading