Add a validation helper function.

I will use this in a subsequent PR as part of #12298
This commit is contained in:
Eric Tune
2016-02-12 14:38:22 -08:00
parent 468d0db8f7
commit 825dc470cc
2 changed files with 51 additions and 0 deletions

View File

@@ -5009,3 +5009,40 @@ func TestValidateConfigMapUpdate(t *testing.T) {
}
}
}
func TestValidateHasLabel(t *testing.T) {
successCase := api.ObjectMeta{
Name: "123",
Namespace: "ns",
Labels: map[string]string{
"other": "blah",
"foo": "bar",
},
}
if errs := ValidateHasLabel(successCase, field.NewPath("field"), "foo", "bar"); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
missingCase := api.ObjectMeta{
Name: "123",
Namespace: "ns",
Labels: map[string]string{
"other": "blah",
},
}
if errs := ValidateHasLabel(missingCase, field.NewPath("field"), "foo", "bar"); len(errs) == 0 {
t.Errorf("expected failure")
}
wrongValueCase := api.ObjectMeta{
Name: "123",
Namespace: "ns",
Labels: map[string]string{
"other": "blah",
"foo": "notbar",
},
}
if errs := ValidateHasLabel(wrongValueCase, field.NewPath("field"), "foo", "bar"); len(errs) == 0 {
t.Errorf("expected failure")
}
}