Skip to content

Commit 8ee0d62

Browse files
authored
Fixes bad initialization for uniqueString (grafana#6432)
1 parent a1c72ad commit 8ee0d62

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/logql/log/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
func uniqueString(s []string) []string {
88
unique := make(map[string]bool, len(s))
9-
us := make([]string, len(unique))
9+
us := make([]string, 0, len(s))
1010
for _, elem := range s {
1111
if len(elem) != 0 {
1212
if !unique[elem] {

pkg/logql/log/util_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package log
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
48

59
func Test_sanitizeLabelKey(t *testing.T) {
610
tests := []struct {
@@ -23,3 +27,10 @@ func Test_sanitizeLabelKey(t *testing.T) {
2327
})
2428
}
2529
}
30+
31+
func Test_UniqueStrings(t *testing.T) {
32+
in := []string{"foo", "bar", "baz", "foo"}
33+
out := uniqueString(in)
34+
require.Equal(t, []string{"foo", "bar", "baz"}, out)
35+
require.Equal(t, 4, cap(out))
36+
}

0 commit comments

Comments
 (0)