Annotations cannot being empty
This commit is contained in:
parent
f78e2e3849
commit
497246f8ba
9 changed files with 28 additions and 26 deletions
|
|
@ -52,6 +52,10 @@ func (a ingAnnotations) parseBool(name string) (bool, error) {
|
|||
func (a ingAnnotations) parseString(name string) (string, error) {
|
||||
val, ok := a[name]
|
||||
if ok {
|
||||
if len(val) == 0 {
|
||||
return "", errors.NewInvalidAnnotationContent(name, val)
|
||||
}
|
||||
|
||||
return val, nil
|
||||
}
|
||||
return "", errors.ErrMissingAnnotations
|
||||
|
|
@ -97,6 +101,7 @@ func GetStringAnnotation(name string, ing *extensions.Ingress) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return ingAnnotations(ing.GetAnnotations()).parseString(v)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
|
||||
_, err := GetStringAnnotation("", nil)
|
||||
if err == nil {
|
||||
t.Errorf("expected error but retuned nil")
|
||||
t.Errorf("expected error but none returned")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
|
|
@ -91,6 +91,7 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
}{
|
||||
{"valid - A", "string", "A", "A", false},
|
||||
{"valid - B", "string", "B", "B", false},
|
||||
{"empty", "string", "", "", true},
|
||||
}
|
||||
|
||||
data := map[string]string{}
|
||||
|
|
@ -102,7 +103,7 @@ func TestGetStringAnnotation(t *testing.T) {
|
|||
s, err := GetStringAnnotation(test.field, ing)
|
||||
if test.expErr {
|
||||
if err == nil {
|
||||
t.Errorf("%v: expected error but retuned nil", test.name)
|
||||
t.Errorf("%v: expected error but none returned", test.name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue