()
| 249 | } |
| 250 | |
| 251 | func (o *UniqueOpts) validate() error { |
| 252 | if o.isEmpty() { |
| 253 | return nil |
| 254 | } |
| 255 | |
| 256 | if o.ByPeriod != time.Duration(0) && o.ByPeriod < 1*time.Second { |
| 257 | return errors.New("UniqueOpts.ByPeriod should not be less than 1 second") |
| 258 | } |
| 259 | |
| 260 | // Job states are typed, but since the underlying type is a string, users |
| 261 | // can put anything they want in there. |
| 262 | for _, state := range o.ByState { |
| 263 | // This could be turned to a map lookup, but last I checked the speed |
| 264 | // difference for tiny slice sizes is negligible, and map lookup might |
| 265 | // even be slower. |
| 266 | if !slices.Contains(jobStateAll, state) { |
| 267 | return fmt.Errorf("UniqueOpts.ByState contains invalid state %q", state) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Skip required states validation if no custom states were provided. |
| 272 | if len(o.ByState) == 0 { |
| 273 | return nil |
| 274 | } |
| 275 | |
| 276 | var missingStates []string |
| 277 | for _, state := range requiredV3states { |
| 278 | if !slices.Contains(o.ByState, state) { |
| 279 | missingStates = append(missingStates, string(state)) |
| 280 | } |
| 281 | } |
| 282 | if len(missingStates) > 0 { |
| 283 | return fmt.Errorf("UniqueOpts.ByState must contain all required states, missing: %s", strings.Join(missingStates, ", ")) |
| 284 | } |
| 285 | |
| 286 | return nil |
| 287 | } |
no test coverage detected