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

Commit

Permalink
Addressing comments + fixing copypasta
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Gromov committed Sep 25, 2017
1 parent fab80b7 commit 332e992
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
10 changes: 5 additions & 5 deletions rules/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
)

var (
errBadMappingRuleSnapshotIdx = errors.New("mapping rule snapshot index out of range")
errNilMappingRuleSnapshotSchema = errors.New("nil mapping rule snapshot schema")
errNilMappingRuleSchema = errors.New("nil mapping rule schema")
errMappingRuleSnapshotIdxOutOfRange = errors.New("mapping rule snapshot index out of range")
errNilMappingRuleSnapshotSchema = errors.New("nil mapping rule snapshot schema")
errNilMappingRuleSchema = errors.New("nil mapping rule schema")
)

// mappingRuleSnapshot defines a rule snapshot such that if a metric matches the
Expand Down Expand Up @@ -146,8 +146,8 @@ type MappingRuleView struct {
}

func (mc *mappingRule) mappingRuleView(snapshotIdx int) (*MappingRuleView, error) {
if snapshotIdx < 0 || snapshotIdx > len(mc.snapshots) {
return nil, errBadMappingRuleSnapshotIdx
if snapshotIdx < 0 || snapshotIdx >= len(mc.snapshots) {
return nil, errMappingRuleSnapshotIdxOutOfRange
}

mrs := mc.snapshots[snapshotIdx].clone()
Expand Down
9 changes: 6 additions & 3 deletions rules/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,12 @@ func TestNewMappingRuleViewError(t *testing.T) {
mr, err := newMappingRule(testMappingRuleSchema, testTagsFilterOptions())
require.NoError(t, err)

actual, err := mr.mappingRuleView(20)
require.Error(t, err)
require.Nil(t, actual)
badIdx := []int{-2, 2, 30}
for _, i := range badIdx {
actual, err := mr.mappingRuleView(i)
require.Error(t, err)
require.Nil(t, actual)
}
}

func TestMappingRuleHistory(t *testing.T) {
Expand Down
24 changes: 12 additions & 12 deletions rules/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ var (
emptyNamespace Namespace
emptyNamespaces Namespaces

errBadNamespaceSnapshotIdx = errors.New("namespace snapshot idx out of range")
errNilNamespaceSnapshotSchema = errors.New("nil namespace snapshot schema")
errNilNamespaceSchema = errors.New("nil namespace schema")
errNilNamespacesSchema = errors.New("nil namespaces schema")
errNilNamespaceSnapshot = errors.New("nil namespace snapshot")
errMultipleNamespaceMatches = errors.New("more than one namespace match found")
errNamespaceNotFound = errors.New("namespace not found")
errNamespaceNotTombstoned = errors.New("not tombstoned")
errNamespaceTombstoned = errors.New("already tombstoned")
errNoNamespaceSnapshots = errors.New("no snapshots")
errNamespaceSnapshotIdxOutOfRange = errors.New("namespace snapshot idx out of range")
errNilNamespaceSnapshotSchema = errors.New("nil namespace snapshot schema")
errNilNamespaceSchema = errors.New("nil namespace schema")
errNilNamespacesSchema = errors.New("nil namespaces schema")
errNilNamespaceSnapshot = errors.New("nil namespace snapshot")
errMultipleNamespaceMatches = errors.New("more than one namespace match found")
errNamespaceNotFound = errors.New("namespace not found")
errNamespaceNotTombstoned = errors.New("not tombstoned")
errNamespaceTombstoned = errors.New("already tombstoned")
errNoNamespaceSnapshots = errors.New("no snapshots")

namespaceActionErrorFmt = "cannot %s namespace %s. %v"
)
Expand Down Expand Up @@ -109,8 +109,8 @@ type NamespaceView struct {
}

func (n Namespace) namespaceView(snapshotIdx int) (*NamespaceView, error) {
if snapshotIdx < 0 || snapshotIdx > len(n.snapshots) {
return nil, errBadNamespaceSnapshotIdx
if snapshotIdx < 0 || snapshotIdx >= len(n.snapshots) {
return nil, errNamespaceSnapshotIdxOutOfRange
}
s := n.snapshots[snapshotIdx]
return &NamespaceView{
Expand Down
2 changes: 1 addition & 1 deletion rules/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func TestNamespaceViewError(t *testing.T) {
},
}

badIdx := []int{30, -2}
badIdx := []int{-2, 2, 30}
for _, i := range badIdx {
actual, err := n.namespaceView(i)
require.Error(t, err)
Expand Down
12 changes: 6 additions & 6 deletions rules/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
var (
emptyRollupTarget RollupTarget

errBadRollupRuleSnapshotIdx = errors.New("rollup rule snapshot index out of range")
errNilRollupTargetSchema = errors.New("nil rollup target schema")
errNilRollupRuleSnapshotSchema = errors.New("nil rollup rule snapshot schema")
errNilRollupRuleSchema = errors.New("nil rollup rule schema")
errRollupRuleSnapshotIdxOutOfRange = errors.New("rollup rule snapshot index out of range")
errNilRollupTargetSchema = errors.New("nil rollup target schema")
errNilRollupRuleSnapshotSchema = errors.New("nil rollup rule snapshot schema")
errNilRollupRuleSchema = errors.New("nil rollup rule schema")
)

// RollupTarget dictates how to roll up metrics. Metrics associated with a rollup
Expand Down Expand Up @@ -268,8 +268,8 @@ type RollupRuleView struct {
}

func (rc *rollupRule) rollupRuleView(snapshotIdx int) (*RollupRuleView, error) {
if snapshotIdx < 0 || snapshotIdx > len(rc.snapshots) {
return nil, errBadRollupRuleSnapshotIdx
if snapshotIdx < 0 || snapshotIdx >= len(rc.snapshots) {
return nil, errRollupRuleSnapshotIdxOutOfRange
}

rrs := rc.snapshots[snapshotIdx].clone()
Expand Down
9 changes: 6 additions & 3 deletions rules/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,12 @@ func TestNewRollupRuleView(t *testing.T) {
func TestNewRollupRuleViewError(t *testing.T) {
rr, err := newRollupRule(testRollupRuleSchema, testTagsFilterOptions())
require.NoError(t, err)
actual, err := rr.rollupRuleView(20)
require.Error(t, err)
require.Nil(t, actual)
badIdx := []int{-2, 2, 30}
for _, i := range badIdx {
actual, err := rr.rollupRuleView(i)
require.Error(t, err)
require.Nil(t, actual)
}
}

func TestNewRollupRuleHistory(t *testing.T) {
Expand Down

0 comments on commit 332e992

Please sign in to comment.