MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestSortLabels

Function TestSortLabels

pkg/distributor/distributor_test.go:4316–4341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4314}
4315
4316func TestSortLabels(t *testing.T) {
4317 sorted := []cortexpb.LabelAdapter{
4318 {Name: "__name__", Value: "foo"},
4319 {Name: "bar", Value: "baz"},
4320 {Name: "cluster", Value: "cluster"},
4321 {Name: "sample", Value: "1"},
4322 }
4323
4324 // no allocations if input is already sorted
4325 require.Equal(t, 0.0, testing.AllocsPerRun(100, func() {
4326 sortLabelsIfNeeded(sorted)
4327 }))
4328
4329 unsorted := []cortexpb.LabelAdapter{
4330 {Name: "__name__", Value: "foo"},
4331 {Name: "sample", Value: "1"},
4332 {Name: "cluster", Value: "cluster"},
4333 {Name: "bar", Value: "baz"},
4334 }
4335
4336 sortLabelsIfNeeded(unsorted)
4337
4338 sort.SliceIsSorted(unsorted, func(i, j int) bool {
4339 return strings.Compare(unsorted[i].Name, unsorted[j].Name) < 0
4340 })
4341}
4342
4343func TestDistributor_Push_Relabel(t *testing.T) {
4344 t.Parallel()

Callers

nothing calls this directly

Calls 3

sortLabelsIfNeededFunction · 0.85
EqualMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected