Skip to content

Commit

Permalink
Add tests for LabelNames and LabelValues to timefilter
Browse files Browse the repository at this point in the history
Tests for #577
  • Loading branch information
jacksontj committed Mar 29, 2023
1 parent dd4613d commit 67072e2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/promclient/timefilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ func timefilterTest(t *testing.T, api API, testCase timeFilterTestCase) {

for i, r := range testCase.validRanges {
t.Run(fmt.Sprintf("validRange_%d", i), func(t *testing.T) {
t.Run("label_names", func(t *testing.T) {
if _, _, err := api.LabelNames(context.TODO(), []string{"a"}, r.Start, r.End); err == nil {
t.Fatalf("Missing call to API")
}
})

t.Run("label_values", func(t *testing.T) {
if _, _, err := api.LabelValues(context.TODO(), "__name__", []string{"a"}, r.Start, r.End); err == nil {
t.Fatalf("Missing call to API")
}
})

t.Run("query_range", func(t *testing.T) {
if _, _, err := api.QueryRange(context.TODO(), "", v1.Range{Start: r.Start, End: r.End}); err == nil {
t.Fatalf("Missing call to API")
Expand All @@ -58,6 +70,18 @@ func timefilterTest(t *testing.T, api API, testCase timeFilterTestCase) {
}
for i, r := range testCase.invalidRanges {
t.Run(fmt.Sprintf("invalidRange_%d", i), func(t *testing.T) {
t.Run("label_names", func(t *testing.T) {
if _, _, err := api.LabelNames(context.TODO(), []string{"a"}, r.Start, r.End); err != nil {
t.Fatalf("Unexpected call to API")
}
})

t.Run("label_values", func(t *testing.T) {
if _, _, err := api.LabelValues(context.TODO(), "__name__", []string{"a"}, r.Start, r.End); err != nil {
t.Fatalf("Unexpected call to API")
}
})

t.Run("query_range", func(t *testing.T) {
if _, _, err := api.QueryRange(context.TODO(), "", v1.Range{Start: r.Start, End: r.End}); err != nil {
t.Fatalf("Unexpected call to API")
Expand Down

0 comments on commit 67072e2

Please sign in to comment.