mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #2526 from erictune/addhelper
Add selector making helper
This commit is contained in:
commit
7ca2e06553
@ -483,3 +483,9 @@ func ParseSelector(selector string) (Selector, error) {
|
||||
}
|
||||
return andTerm(items), nil
|
||||
}
|
||||
|
||||
// OneTermEqualSelector returns an object that matches objects where one label/field equals one value.
|
||||
// Cannot return an error.
|
||||
func OneTermEqualSelector(k, v string) Selector {
|
||||
return &hasTerm{label: k, value: v}
|
||||
}
|
||||
|
@ -113,6 +113,15 @@ func TestSelectorMatches(t *testing.T) {
|
||||
expectNoMatch(t, "foo=bar,foobar=bar,baz=blah", labelset)
|
||||
}
|
||||
|
||||
func TestOneTermEqualSelector(t *testing.T) {
|
||||
if !OneTermEqualSelector("x", "y").Matches(Set{"x": "y"}) {
|
||||
t.Errorf("No match when match expected.")
|
||||
}
|
||||
if OneTermEqualSelector("x", "y").Matches(Set{"x": "z"}) {
|
||||
t.Errorf("Match when none expected.")
|
||||
}
|
||||
}
|
||||
|
||||
func expectMatchDirect(t *testing.T, selector, ls Set) {
|
||||
if !SelectorFromSet(selector).Matches(ls) {
|
||||
t.Errorf("Wanted %s to match '%s', but it did not.\n", selector, ls)
|
||||
|
Loading…
Reference in New Issue
Block a user