diff --git a/pkg/expr/commands_test.go b/pkg/expr/commands_test.go index aa741dada2e..9109e6fc6ec 100644 --- a/pkg/expr/commands_test.go +++ b/pkg/expr/commands_test.go @@ -169,7 +169,7 @@ func TestReduceExecute(t *testing.T) { func randomReduceFunc() string { res := mathexp.GetSupportedReduceFuncs() - return res[rand.Intn(len(res)-1)] + return res[rand.Intn(len(res))] } func TestResampleCommand_Execute(t *testing.T) { diff --git a/pkg/services/ngalert/api/api_ruler_validation_test.go b/pkg/services/ngalert/api/api_ruler_validation_test.go index b5098d167f4..00d76433882 100644 --- a/pkg/services/ngalert/api/api_ruler_validation_test.go +++ b/pkg/services/ngalert/api/api_ruler_validation_test.go @@ -69,8 +69,8 @@ func validRule() apimodels.PostableExtendedRuleNode { }, }, UID: util.GenerateShortUID(), - NoDataState: allNoData[rand.Intn(len(allNoData)-1)], - ExecErrState: allExecError[rand.Intn(len(allExecError)-1)], + NoDataState: allNoData[rand.Intn(len(allNoData))], + ExecErrState: allExecError[rand.Intn(len(allExecError))], }, } } diff --git a/pkg/services/ngalert/api/util_test.go b/pkg/services/ngalert/api/util_test.go index 3ed32d797e6..ce79d0fed9f 100644 --- a/pkg/services/ngalert/api/util_test.go +++ b/pkg/services/ngalert/api/util_test.go @@ -163,14 +163,15 @@ func Test_containsProvisionedAlerts(t *testing.T) { t.Run("should return true if at least one rule is provisioned", func(t *testing.T) { _, rules := models2.GenerateUniqueAlertRules(rand.Intn(4)+2, models2.AlertRuleGen()) provenance := map[string]models2.Provenance{ - rules[rand.Intn(len(rules)-1)].UID: []models2.Provenance{models2.ProvenanceAPI, models2.ProvenanceFile}[rand.Intn(2)], + rules[rand.Intn(len(rules))].UID: []models2.Provenance{models2.ProvenanceAPI, models2.ProvenanceFile}[rand.Intn(2)], } require.Truef(t, containsProvisionedAlerts(provenance, rules), "the group of rules is expected to be considered as provisioned but it isn't. Provenances: %v", provenance) }) t.Run("should return false if map does not contain or has ProvenanceNone", func(t *testing.T) { _, rules := models2.GenerateUniqueAlertRules(rand.Intn(5)+1, models2.AlertRuleGen()) provenance := make(map[string]models2.Provenance) - for i := 0; i < rand.Intn(len(rules)); i++ { + numProvenanceNone := rand.Intn(len(rules)) + for i := 0; i < numProvenanceNone; i++ { provenance[rules[i].UID] = models2.ProvenanceNone } require.Falsef(t, containsProvisionedAlerts(provenance, rules), "the group of rules is not expected to be provisioned but it is. Provenances: %v", provenance) diff --git a/pkg/services/ngalert/models/testing.go b/pkg/services/ngalert/models/testing.go index 82b0ab7d443..6c1ed0c7897 100644 --- a/pkg/services/ngalert/models/testing.go +++ b/pkg/services/ngalert/models/testing.go @@ -25,7 +25,7 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule { NoData, OK, } - return s[rand.Intn(len(s)-1)] + return s[rand.Intn(len(s))] } randErrState := func() ExecutionErrorState { @@ -34,7 +34,7 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule { ErrorErrState, OkErrState, } - return s[rand.Intn(len(s)-1)] + return s[rand.Intn(len(s))] } interval := (rand.Int63n(6) + 1) * 10 diff --git a/pkg/services/ngalert/store/deltas_test.go b/pkg/services/ngalert/store/deltas_test.go index 6f066d9907a..d3e63758e88 100644 --- a/pkg/services/ngalert/store/deltas_test.go +++ b/pkg/services/ngalert/store/deltas_test.go @@ -328,7 +328,7 @@ func TestCalculateAutomaticChanges(t *testing.T) { group2 := models.GenerateGroupKey(orgID) rules2 := models.GenerateAlertRules(4, models.AlertRuleGen(withGroupKey(group2), models.WithSequentialGroupIndex())) - movedIndex := rand.Intn(len(rules2) - 1) + movedIndex := rand.Intn(len(rules2)) movedRule := rules2[movedIndex] copyRule := models.CopyRule(movedRule) copyRule.RuleGroup = group.RuleGroup