-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure metrics labels are sorted (#45)
* Ensure metrics labels are sorted Signed-off-by: Matej Gera <matejgera@gmail.com> * Add small unit test Signed-off-by: Matej Gera <matejgera@gmail.com>
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package options | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/efficientgo/tools/core/pkg/testutil" | ||
"github.com/prometheus/prometheus/prompb" | ||
) | ||
|
||
func TestLabelArg_Sort(t *testing.T) { | ||
testCases := []struct { | ||
original labelArg | ||
expected labelArg | ||
}{ | ||
{ | ||
// Test sorting with lower-case label names (__name__ should be first). | ||
labelArg{ | ||
prompb.Label{Name: "z", Value: "1"}, | ||
prompb.Label{Name: "a", Value: "1"}, | ||
prompb.Label{Name: "__name__", Value: "test"}, | ||
}, | ||
labelArg{ | ||
prompb.Label{Name: "__name__", Value: "test"}, | ||
prompb.Label{Name: "a", Value: "1"}, | ||
prompb.Label{Name: "z", Value: "1"}, | ||
}, | ||
}, | ||
{ | ||
// Test sorting with upper-case label names (upper case should be first). | ||
labelArg{ | ||
prompb.Label{Name: "__name__", Value: "test"}, | ||
prompb.Label{Name: "A", Value: "1"}, | ||
prompb.Label{Name: "b", Value: "1"}, | ||
}, | ||
labelArg{ | ||
prompb.Label{Name: "A", Value: "1"}, | ||
prompb.Label{Name: "__name__", Value: "test"}, | ||
prompb.Label{Name: "b", Value: "1"}, | ||
}, | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
t.Run(fmt.Sprintf("case #%d", i), func(t *testing.T) { | ||
tc.original.Sort() | ||
testutil.Equals(t, tc.expected, tc.original) | ||
}) | ||
} | ||
} |