Merge pull request #21199 from erictune/validation-helper
Auto commit by PR queue bot
This commit is contained in:
@@ -5107,3 +5107,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")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user