Skip to content

Commit

Permalink
Fixes bad initialization for uniqueString (#6432)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Jun 20, 2022
1 parent a1c72ad commit 8ee0d62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/logql/log/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

func uniqueString(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, len(unique))
us := make([]string, 0, len(s))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
Expand Down
13 changes: 12 additions & 1 deletion pkg/logql/log/util_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package log

import "testing"
import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_sanitizeLabelKey(t *testing.T) {
tests := []struct {
Expand All @@ -23,3 +27,10 @@ func Test_sanitizeLabelKey(t *testing.T) {
})
}
}

func Test_UniqueStrings(t *testing.T) {
in := []string{"foo", "bar", "baz", "foo"}
out := uniqueString(in)
require.Equal(t, []string{"foo", "bar", "baz"}, out)
require.Equal(t, 4, cap(out))
}

0 comments on commit 8ee0d62

Please sign in to comment.