Fix compareLabels, add test
This commit is contained in:
parent
fc992fafc2
commit
725385ea05
|
@ -182,7 +182,7 @@ func compareLabels(a, b Labels) int {
|
|||
}
|
||||
}
|
||||
// If all labels so far were in common, the set with fewer labels comes first.
|
||||
return len(b) - len(a)
|
||||
return len(a) - len(b)
|
||||
}
|
||||
|
||||
func (s *shardSeriesSet) Series() Series {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package tsdb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCompareLabels(t *testing.T) {
|
||||
cases := []struct {
|
||||
a, b []Label
|
||||
res int
|
||||
}{
|
||||
{
|
||||
a: []Label{},
|
||||
b: []Label{},
|
||||
res: 0,
|
||||
},
|
||||
{
|
||||
a: []Label{{"a", ""}},
|
||||
b: []Label{{"a", ""}, {"b", ""}},
|
||||
res: -1,
|
||||
},
|
||||
{
|
||||
a: []Label{{"a", ""}},
|
||||
b: []Label{{"a", ""}},
|
||||
res: 0,
|
||||
},
|
||||
{
|
||||
a: []Label{{"aa", ""}, {"aa", ""}},
|
||||
b: []Label{{"aa", ""}, {"ab", ""}},
|
||||
res: -1,
|
||||
},
|
||||
{
|
||||
a: []Label{{"aa", ""}, {"abb", ""}},
|
||||
b: []Label{{"aa", ""}, {"ab", ""}},
|
||||
res: 1,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
// Use constructor to ensure sortedness.
|
||||
a, b := NewLabels(c.a...), NewLabels(c.b...)
|
||||
|
||||
require.Equal(t, c.res, compareLabels(a, b))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue