Fix test due to map iteration

Signed-off-by: Joel Whittaker-Smith <jdws.dev@gmail.com>
This commit is contained in:
Joel Whittaker-Smith 2020-10-08 23:35:28 +02:00
parent 5d56275d2b
commit 2826d10f65
1 changed files with 8 additions and 4 deletions

View File

@ -49,7 +49,7 @@ func (a Labels) Allowed(metric string, labels, values []string) ([]string, []str
var finalLabels, finalValues []string
labelSet := labelSet(allowedLabels)
for allowedLabel := range labelSet {
for _, allowedLabel := range labelSet {
for i, label := range labels {
if label == allowedLabel {
finalLabels = append(finalLabels, label)
@ -61,12 +61,16 @@ func (a Labels) Allowed(metric string, labels, values []string) ([]string, []str
return finalLabels, finalValues
}
func labelSet(lists ...[]string) map[string]interface{} {
func labelSet(lists ...[]string) []string {
m := make(map[string]interface{})
var set []string
for _, list := range lists {
for _, e := range list {
m[e] = struct{}{}
if _, ok := m[e]; !ok {
m[e] = struct{}{}
set = append(set, e)
}
}
}
return m
return set
}