Skip to content

Commit

Permalink
pkg/names: test namespaced external metrics selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed May 17, 2019
1 parent 4863247 commit 5bb6671
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pkg/naming/metrics_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type resourceConverterMock struct {
// ResourcesForSeries is a mock that returns a single group resource,
// namely the series as a resource itself.
func (rcm *resourceConverterMock) ResourcesForSeries(series prom.Series) (res []schema.GroupResource, namespaced bool) {
return []schema.GroupResource{{Resource: series.Name}}, false
return []schema.GroupResource{{Resource: series.Name}}, rcm.namespaced
}

// LabelForResource is a mock that returns the label name,
Expand Down Expand Up @@ -300,6 +300,19 @@ func TestBuildExternalSelector(t *testing.T) {
hasSelector("[foo bar]"),
),
},
{
name: "multiple GroupBySlice values with namespace",

mq: mustNewQuery(`<<index .LabelValuesByName "namespaces">> <<.GroupBySlice>>`, true),
namespace: "default",
groupBySlice: []string{"foo", "bar"},
metricSelector: labels.NewSelector(),

check: checks(
hasError(nil),
hasSelector("default [foo bar]"),
),
},
{
name: "single LabelMatchers value",

Expand All @@ -313,6 +326,20 @@ func TestBuildExternalSelector(t *testing.T) {
hasSelector(`foo="bar"`),
),
},
{
name: "single LabelMatchers value with namespace",

mq: mustNewQuery(`<<.LabelMatchers>>`, true),
namespace: "default",
metricSelector: labels.NewSelector().Add(
*mustNewLabelRequirement("foo", selection.Equals, []string{"bar"}),
),

check: checks(
hasError(nil),
hasSelector(`foo="bar",namespaces="default"`),
),
},
{
name: "multiple LabelMatchers value",

Expand Down

0 comments on commit 5bb6671

Please sign in to comment.