(rules []*pushrules.Rule, afterID, beforeID string)
| 346 | } |
| 347 | |
| 348 | func findPushRuleInsertionIndex(rules []*pushrules.Rule, afterID, beforeID string) (int, error) { |
| 349 | var i int |
| 350 | |
| 351 | if afterID != "" { |
| 352 | for ; i < len(rules); i++ { |
| 353 | if rules[i].RuleID == afterID { |
| 354 | break |
| 355 | } |
| 356 | } |
| 357 | if i == len(rules) { |
| 358 | return 0, jsonerror.NotFound("after: rule ID not found") |
| 359 | } |
| 360 | if rules[i].Default { |
| 361 | return 0, jsonerror.NotFound("after: rule ID must not be a default rule") |
| 362 | } |
| 363 | // We stopped on the "after" match to differentiate |
| 364 | // not-found from is-last-entry. Now we move to the earliest |
| 365 | // insertion point. |
| 366 | i++ |
| 367 | } |
| 368 | |
| 369 | if beforeID != "" { |
| 370 | for ; i < len(rules); i++ { |
| 371 | if rules[i].RuleID == beforeID { |
| 372 | break |
| 373 | } |
| 374 | } |
| 375 | if i == len(rules) { |
| 376 | return 0, jsonerror.NotFound("before: rule ID not found") |
| 377 | } |
| 378 | if rules[i].Default { |
| 379 | return 0, jsonerror.NotFound("before: rule ID must not be a default rule") |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // UNSPEC: The spec does not say what to do if no after/before is |
| 384 | // given. Sytest fails if it doesn't go first. |
| 385 | return i, nil |
| 386 | } |
no outgoing calls
no test coverage detected