mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Rename LabelSet labels.Set
This commit is contained in:
@@ -26,11 +26,11 @@ type Labels interface {
|
||||
}
|
||||
|
||||
// A map of label:value. Implements Labels.
|
||||
type LabelSet map[string]string
|
||||
type Set map[string]string
|
||||
|
||||
// All labels listed as a human readable string. Conveiently, exactly the format
|
||||
// that ParseQuery takes.
|
||||
func (ls LabelSet) String() string {
|
||||
func (ls Set) String() string {
|
||||
query := make([]string, 0, len(ls))
|
||||
for key, value := range ls {
|
||||
query = append(query, key+"="+value)
|
||||
@@ -39,6 +39,6 @@ func (ls LabelSet) String() string {
|
||||
}
|
||||
|
||||
// Implement Labels interface.
|
||||
func (ls LabelSet) Get(label string) string {
|
||||
func (ls Set) Get(label string) string {
|
||||
return ls[label]
|
||||
}
|
||||
|
||||
@@ -20,24 +20,24 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func matches(t *testing.T, ls LabelSet, want string) {
|
||||
func matches(t *testing.T, ls Set, want string) {
|
||||
if ls.String() != want {
|
||||
t.Errorf("Expected '%s', but got '%s'", want, ls.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelSetString(t *testing.T) {
|
||||
matches(t, LabelSet{"x": "y"}, "x=y")
|
||||
matches(t, LabelSet{"foo": "bar"}, "foo=bar")
|
||||
matches(t, LabelSet{"foo": "bar", "baz": "qup"}, "foo=bar,baz=qup")
|
||||
func TestSetString(t *testing.T) {
|
||||
matches(t, Set{"x": "y"}, "x=y")
|
||||
matches(t, Set{"foo": "bar"}, "foo=bar")
|
||||
matches(t, Set{"foo": "bar", "baz": "qup"}, "foo=bar,baz=qup")
|
||||
|
||||
// TODO: Make our label representation robust enough to handel labels
|
||||
// with ",=!" characters in their names.
|
||||
}
|
||||
|
||||
func TestLabelGet(t *testing.T) {
|
||||
ls := LabelSet{"x": "y"}
|
||||
ls := Set{"x": "y"}
|
||||
if ls.Get("x") != "y" {
|
||||
t.Errorf("LabelSet.Get is broken")
|
||||
t.Errorf("Set.Get is broken")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type queryTerm struct {
|
||||
|
||||
// Exactly one of the below three items should be used.
|
||||
|
||||
// If non-nil, we match LabelSet l iff l[*label] == *value.
|
||||
// If non-nil, we match Set l iff l[*label] == *value.
|
||||
label, value *string
|
||||
|
||||
// A list of terms which must all match for this query term to return true.
|
||||
@@ -89,8 +89,8 @@ func try(queryPiece, op string) (lhs, rhs string, ok bool) {
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
// Given a LabelSet, return a Query which will match exactly that LabelSet.
|
||||
func QueryFromSet(ls LabelSet) Query {
|
||||
// Given a Set, return a Query which will match exactly that Set.
|
||||
func QueryFromSet(ls Set) Query {
|
||||
var query queryTerm
|
||||
for l, v := range ls {
|
||||
// Make a copy, because we're taking the address below
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestQueryParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func expectMatch(t *testing.T, query string, ls LabelSet) {
|
||||
func expectMatch(t *testing.T, query string, ls Set) {
|
||||
lq, err := ParseQuery(query)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to parse %v as a query\n", query)
|
||||
@@ -58,7 +58,7 @@ func expectMatch(t *testing.T, query string, ls LabelSet) {
|
||||
}
|
||||
}
|
||||
|
||||
func expectNoMatch(t *testing.T, query string, ls LabelSet) {
|
||||
func expectNoMatch(t *testing.T, query string, ls Set) {
|
||||
lq, err := ParseQuery(query)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to parse %v as a query\n", query)
|
||||
@@ -70,21 +70,21 @@ func expectNoMatch(t *testing.T, query string, ls LabelSet) {
|
||||
}
|
||||
|
||||
func TestEverything(t *testing.T) {
|
||||
if !Everything().Matches(LabelSet{"x": "y"}) {
|
||||
if !Everything().Matches(Set{"x": "y"}) {
|
||||
t.Errorf("Nil query didn't match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelQueryMatches(t *testing.T) {
|
||||
expectMatch(t, "", LabelSet{"x": "y"})
|
||||
expectMatch(t, "x=y", LabelSet{"x": "y"})
|
||||
expectMatch(t, "x=y,z=w", LabelSet{"x": "y", "z": "w"})
|
||||
expectMatch(t, "x!=y,z!=w", LabelSet{"x": "z", "z": "a"})
|
||||
expectNoMatch(t, "x=y", LabelSet{"x": "z"})
|
||||
expectNoMatch(t, "x=y,z=w", LabelSet{"x": "w", "z": "w"})
|
||||
expectNoMatch(t, "x!=y,z!=w", LabelSet{"x": "z", "z": "w"})
|
||||
expectMatch(t, "", Set{"x": "y"})
|
||||
expectMatch(t, "x=y", Set{"x": "y"})
|
||||
expectMatch(t, "x=y,z=w", Set{"x": "y", "z": "w"})
|
||||
expectMatch(t, "x!=y,z!=w", Set{"x": "z", "z": "a"})
|
||||
expectNoMatch(t, "x=y", Set{"x": "z"})
|
||||
expectNoMatch(t, "x=y,z=w", Set{"x": "w", "z": "w"})
|
||||
expectNoMatch(t, "x!=y,z!=w", Set{"x": "z", "z": "w"})
|
||||
|
||||
labelset := LabelSet{
|
||||
labelset := Set{
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
}
|
||||
@@ -96,28 +96,28 @@ func TestLabelQueryMatches(t *testing.T) {
|
||||
expectNoMatch(t, "foo=bar,foobar=bar,baz=blah", labelset)
|
||||
}
|
||||
|
||||
func expectMatchDirect(t *testing.T, query, ls LabelSet) {
|
||||
func expectMatchDirect(t *testing.T, query, ls Set) {
|
||||
if !QueryFromSet(query).Matches(ls) {
|
||||
t.Errorf("Wanted %s to match '%s', but it did not.\n", query, ls)
|
||||
}
|
||||
}
|
||||
|
||||
func expectNoMatchDirect(t *testing.T, query, ls LabelSet) {
|
||||
func expectNoMatchDirect(t *testing.T, query, ls Set) {
|
||||
if QueryFromSet(query).Matches(ls) {
|
||||
t.Errorf("Wanted '%s' to not match '%s', but it did.", query, ls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelSetMatches(t *testing.T) {
|
||||
labelset := LabelSet{
|
||||
func TestSetMatches(t *testing.T) {
|
||||
labelset := Set{
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
}
|
||||
expectMatchDirect(t, LabelSet{}, labelset)
|
||||
expectMatchDirect(t, LabelSet{"foo": "bar"}, labelset)
|
||||
expectMatchDirect(t, LabelSet{"baz": "blah"}, labelset)
|
||||
expectMatchDirect(t, LabelSet{"foo": "bar", "baz": "blah"}, labelset)
|
||||
expectNoMatchDirect(t, LabelSet{"foo": "=blah"}, labelset)
|
||||
expectNoMatchDirect(t, LabelSet{"baz": "=bar"}, labelset)
|
||||
expectNoMatchDirect(t, LabelSet{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset)
|
||||
expectMatchDirect(t, Set{}, labelset)
|
||||
expectMatchDirect(t, Set{"foo": "bar"}, labelset)
|
||||
expectMatchDirect(t, Set{"baz": "blah"}, labelset)
|
||||
expectMatchDirect(t, Set{"foo": "bar", "baz": "blah"}, labelset)
|
||||
expectNoMatchDirect(t, Set{"foo": "=blah"}, labelset)
|
||||
expectNoMatchDirect(t, Set{"baz": "=bar"}, labelset)
|
||||
expectNoMatchDirect(t, Set{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user