Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
remove ptr function from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Skelcy committed Apr 10, 2018
1 parent b4d0d53 commit 2b859a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func NewValidationError(str string) error { return ValidationError(str) }
func (e ValidationError) Error() string { return string(e) }

// StaleDataError is returned when a rule modification can not be completed
// because rule meta data is no longer valid.
// because rule metadata is no longer valid.
type StaleDataError string

// NewStaleDataError creates a new version mismatch error.
func NewStaleDataError(str string) error { return StaleDataError(str) }
func (e StaleDataError) Error() string { return string(e) }

// InvalidChangeError is returned when a change is applied to a ruleset,
// mapping rule, or rollup rule that is invalide.
// mapping rule, or rollup rule that is invalid.
type InvalidChangeError string

// NewInvalidChangeError careats a new invalid change error.
Expand Down
36 changes: 16 additions & 20 deletions rules/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3036,9 +3036,9 @@ func TestRuleSetClone(t *testing.T) {
func TestApplyChanges(t *testing.T) {
mutable, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
ruleSetChangesWithAddOps(&changes, "rrID1", "mrID1")
ruleSetChangesWithUpdateOps(&changes, "rollupRule1", "mappingRule1")
rulesetChangesWithDeletes(&changes, "rollupRule3", "mappingRule3")
testRuleSetChangesWithAddOps(&changes, "rrID1", "mrID1")
testRuleSetChangesWithUpdateOps(&changes, "rollupRule1", "mappingRule1")
testRulesetChangesWithDeletes(&changes, "rollupRule3", "mappingRule3")

err := mutable.ApplyChanges(
changes,
Expand Down Expand Up @@ -3073,7 +3073,7 @@ func TestApplyChanges(t *testing.T) {
func TestApplyMappingRuleChangesAddFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
ruleSetChangesWithAddOps(&changes, "", "mappingRule1")
testRuleSetChangesWithAddOps(&changes, "", "mappingRule1")
changes.MappingRuleChanges[0].RuleData.Name = "mappingRule1.snapshot3"

err := rs.applyMappingRuleChanges(
Expand All @@ -3092,7 +3092,7 @@ func TestApplyMappingRuleChangesAddFailure(t *testing.T) {
func TestApplyRollupRuleChangesAddFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
ruleSetChangesWithAddOps(&changes, "rollupRule1", "")
testRuleSetChangesWithAddOps(&changes, "rollupRule1", "")
changes.RollupRuleChanges[0].RuleData.Name = "rollupRule1.snapshot3"

err := rs.applyRollupRuleChanges(
Expand All @@ -3111,7 +3111,7 @@ func TestApplyRollupRuleChangesAddFailure(t *testing.T) {
func TestApplyMappingRuleChangesDeleteFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
rulesetChangesWithDeletes(&changes, "", "mappingRule1")
testRulesetChangesWithDeletes(&changes, "", "mappingRule1")

err := rs.DeleteMappingRule(
"mappingRule1",
Expand All @@ -3135,7 +3135,7 @@ func TestApplyMappingRuleChangesDeleteFailure(t *testing.T) {
func TestApplyRollupRuleChangesDeleteFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
rulesetChangesWithDeletes(&changes, "rollupRule1", "")
testRulesetChangesWithDeletes(&changes, "rollupRule1", "")

err := rs.DeleteRollupRule(
"rollupRule1",
Expand All @@ -3159,7 +3159,7 @@ func TestApplyRollupRuleChangesDeleteFailure(t *testing.T) {
func TestApplyMappingRuleChangesUpdateFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
ruleSetChangesWithUpdateOps(&changes, "", "invalideMappingRule")
testRuleSetChangesWithUpdateOps(&changes, "", "invalideMappingRule")

err := rs.applyMappingRuleChanges(
changes.MappingRuleChanges,
Expand All @@ -3176,7 +3176,7 @@ func TestApplyMappingRuleChangesUpdateFailure(t *testing.T) {
func TestApplyRollupRuleChangesUpdateFailure(t *testing.T) {
_, rs, helper, _ := initMutableTest()
changes := changes.RuleSetChanges{}
ruleSetChangesWithUpdateOps(&changes, "invalidRollupRule", "")
testRuleSetChangesWithUpdateOps(&changes, "invalidRollupRule", "")

err := rs.applyRollupRuleChanges(
changes.RollupRuleChanges,
Expand Down Expand Up @@ -3222,7 +3222,7 @@ func TestApplyMappingRuleWithInvalidOp(t *testing.T) {
require.IsType(t, errors.NewInvalidChangeError(""), err)
}

func ruleSetChangesWithAddOps(rsc *changes.RuleSetChanges, rrIDToAdd, mrIDToAdd string) {
func testRuleSetChangesWithAddOps(rsc *changes.RuleSetChanges, rrIDToAdd, mrIDToAdd string) {
if rrIDToAdd != "" {
rsc.RollupRuleChanges = append(
rsc.RollupRuleChanges,
Expand Down Expand Up @@ -3250,13 +3250,13 @@ func ruleSetChangesWithAddOps(rsc *changes.RuleSetChanges, rrIDToAdd, mrIDToAdd
}
}

func ruleSetChangesWithUpdateOps(rsc *changes.RuleSetChanges, rrIDToUpdate, mrIDToUpdate string) {
func testRuleSetChangesWithUpdateOps(rsc *changes.RuleSetChanges, rrIDToUpdate, mrIDToUpdate string) {
if rrIDToUpdate != "" {
rsc.RollupRuleChanges = append(
rsc.RollupRuleChanges,
changes.RollupRuleChange{
Op: changes.ChangeOp,
RuleID: ptr(rrIDToUpdate),
RuleID: &rrIDToUpdate,
RuleData: &models.RollupRule{
ID: rrIDToUpdate,
Name: "updatedRollupRule",
Expand All @@ -3270,7 +3270,7 @@ func ruleSetChangesWithUpdateOps(rsc *changes.RuleSetChanges, rrIDToUpdate, mrID
rsc.MappingRuleChanges,
changes.MappingRuleChange{
Op: changes.ChangeOp,
RuleID: ptr(mrIDToUpdate),
RuleID: &mrIDToUpdate,
RuleData: &models.MappingRule{
ID: mrIDToUpdate,
Name: "updatedMappingRule",
Expand All @@ -3280,13 +3280,13 @@ func ruleSetChangesWithUpdateOps(rsc *changes.RuleSetChanges, rrIDToUpdate, mrID
}
}

func rulesetChangesWithDeletes(rsc *changes.RuleSetChanges, rrIDToDelete, mrIDToDelete string) {
func testRulesetChangesWithDeletes(rsc *changes.RuleSetChanges, rrIDToDelete, mrIDToDelete string) {
if rrIDToDelete != "" {
rsc.RollupRuleChanges = append(
rsc.RollupRuleChanges,
changes.RollupRuleChange{
Op: changes.DeleteOp,
RuleID: ptr(rrIDToDelete),
RuleID: &rrIDToDelete,
},
)
}
Expand All @@ -3296,16 +3296,12 @@ func rulesetChangesWithDeletes(rsc *changes.RuleSetChanges, rrIDToDelete, mrIDTo
rsc.MappingRuleChanges,
changes.MappingRuleChange{
Op: changes.DeleteOp,
RuleID: ptr(mrIDToDelete),
RuleID: &mrIDToDelete,
},
)
}
}

func ptr(s string) *string {
return &s
}

type testMappingsData struct {
id string
matchFrom int64
Expand Down

0 comments on commit 2b859a9

Please sign in to comment.