(val []string, v *StringListValidation)
| 91 | } |
| 92 | |
| 93 | func validateStringList(val []string, v *StringListValidation) ([]string, error) { |
| 94 | if v.RequireCortexResources { |
| 95 | if err := checkOnlyCortexResources(val); err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | } else if !v.AllowCortexResources { |
| 99 | if err := checkNoCortexResources(val); err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if !v.AllowEmpty { |
| 105 | if val != nil && len(val) == 0 { |
| 106 | return nil, ErrorCannotBeEmpty() |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if v.DisallowDups { |
| 111 | if dups := slices.FindDuplicateStrs(val); len(dups) > 0 { |
| 112 | return nil, ErrorDuplicatedValue(dups[0]) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if v.MinLength != 0 { |
| 117 | if len(val) < v.MinLength { |
| 118 | return nil, ErrorTooFewElements(v.MinLength) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if v.MaxLength != 0 { |
| 123 | if len(val) > v.MaxLength { |
| 124 | return nil, ErrorTooManyElements(v.MaxLength) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | for _, invalidLength := range v.InvalidLengths { |
| 129 | if len(val) == invalidLength { |
| 130 | return nil, ErrorWrongNumberOfElements(v.InvalidLengths) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | if v.ElementStringValidation != nil { |
| 135 | for i, element := range val { |
| 136 | err := ValidateStringVal(element, v.ElementStringValidation) |
| 137 | if err != nil { |
| 138 | return nil, errors.Wrap(err, s.Index(i)) |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if v.Validator != nil { |
| 144 | return v.Validator(val) |
| 145 | } |
| 146 | return val, nil |
| 147 | } |
no test coverage detected