mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-14 07:17:52 -08:00
47 lines
768 B
Go
47 lines
768 B
Go
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))
|
|
}
|
|
}
|