summaryrefslogtreecommitdiffhomepage
path: root/policy/policy_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'policy/policy_test.go')
-rw-r--r--policy/policy_test.go65
1 files changed, 36 insertions, 29 deletions
diff --git a/policy/policy_test.go b/policy/policy_test.go
index ebabb3c8..ae615935 100644
--- a/policy/policy_test.go
+++ b/policy/policy_test.go
@@ -16,17 +16,17 @@
package policy
import (
+ "fmt"
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"github.com/osrg/gobgp/table"
"github.com/stretchr/testify/assert"
+ "math"
"net"
"strconv"
"strings"
"testing"
- "fmt"
- "math"
)
func TestPrefixCalcurateNoRange(t *testing.T) {
@@ -277,7 +277,7 @@ func TestPolicyNotMatch(t *testing.T) {
match, pType, newPath := p.Apply(path)
assert.Equal(t, false, match)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
}
func TestPolicyMatchAndReject(t *testing.T) {
@@ -334,7 +334,7 @@ func TestPolicyMatchAndReject(t *testing.T) {
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
}
func TestPolicyMatchAndAccept(t *testing.T) {
@@ -454,12 +454,12 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) {
match, pType, newPath := p.Apply(path1)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
match2, pType2, newPath2 := p.Apply(path2)
assert.Equal(t, false, match2)
assert.Equal(t, ROUTE_TYPE_NONE, pType2)
- assert.Equal(t, nil, newPath2)
+ assert.Nil(t, newPath2)
}
func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
@@ -520,12 +520,12 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
match, pType, newPath := p.Apply(path1)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
match2, pType2, newPath2 := p.Apply(path2)
assert.Equal(t, false, match2)
assert.Equal(t, ROUTE_TYPE_NONE, pType2)
- assert.Equal(t, nil, newPath2)
+ assert.Nil(t, newPath2)
}
func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) {
@@ -623,12 +623,12 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) {
match1, pType1, newPath1 := p.Apply(pathIPv4)
assert.Equal(t, true, match1)
assert.Equal(t, ROUTE_TYPE_REJECT, pType1)
- assert.Equal(t, nil, newPath1)
+ assert.Nil(t, newPath1)
match2, pType2, newPath2 := p.Apply(pathIPv6)
assert.Equal(t, true, match2)
assert.Equal(t, ROUTE_TYPE_REJECT, pType2)
- assert.Equal(t, nil, newPath2)
+ assert.Nil(t, newPath2)
}
func TestAsPathLengthConditionEvaluate(t *testing.T) {
@@ -754,7 +754,7 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) {
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
}
@@ -920,7 +920,7 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) {
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
}
@@ -1141,18 +1141,17 @@ func TestConditionConditionEvaluateWithOtherCondition(t *testing.T) {
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
df = pl.DefinedSets
p = NewPolicy(pl.PolicyDefinitionList[1], df)
match, pType, newPath = p.Apply(path)
assert.Equal(t, false, match)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
- assert.Equal(t, nil, newPath)
+ assert.Nil(t, newPath)
}
-
func TestPolicyMatchAndAddCommunities(t *testing.T) {
// create path
@@ -1203,7 +1202,7 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) {
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
Communities: []string{community},
- Options: "ADD",
+ Options: "ADD",
},
},
},
@@ -1222,7 +1221,6 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) {
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunities())
}
-
func TestPolicyMatchAndReplaceCommunities(t *testing.T) {
// create path
@@ -1276,7 +1274,7 @@ func TestPolicyMatchAndReplaceCommunities(t *testing.T) {
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
Communities: []string{community},
- Options: "REPLACE",
+ Options: "REPLACE",
},
},
},
@@ -1348,7 +1346,7 @@ func TestPolicyMatchAndRemoveCommunities(t *testing.T) {
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
Communities: []string{community1},
- Options: "REMOVE",
+ Options: "REMOVE",
},
},
},
@@ -1420,7 +1418,7 @@ func TestPolicyMatchAndClearCommunities(t *testing.T) {
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
Communities: []string{community1},
- Options: "NULL",
+ Options: "NULL",
},
},
},
@@ -1507,8 +1505,9 @@ func TestPolicyMatchAndReplaceMed(t *testing.T) {
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
-
- newMed := fmt.Sprintf("%d", newPath.GetMed())
+ v, err := newPath.GetMed()
+ assert.Nil(t, err)
+ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, m, newMed)
}
@@ -1576,7 +1575,9 @@ func TestPolicyMatchAndAddingMed(t *testing.T) {
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- newMed := fmt.Sprintf("%d", newPath.GetMed())
+ v, err := newPath.GetMed()
+ assert.Nil(t, err)
+ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed)
}
@@ -1617,7 +1618,7 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) {
NeighborSetList: []config.NeighborSet{ns},
}
- m := fmt.Sprintf("+%d",math.MaxUint32)
+ m := fmt.Sprintf("+%d", math.MaxUint32)
ma := "1"
s := config.Statement{
Name: "statement1",
@@ -1644,7 +1645,9 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) {
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- newMed := fmt.Sprintf("%d", newPath.GetMed())
+ v, err := newPath.GetMed()
+ assert.Nil(t, err)
+ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed)
}
@@ -1712,7 +1715,9 @@ func TestPolicyMatchAndSubtractMed(t *testing.T) {
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- newMed := fmt.Sprintf("%d", newPath.GetMed())
+ v, err := newPath.GetMed()
+ assert.Nil(t, err)
+ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed)
}
@@ -1780,7 +1785,9 @@ func TestPolicyMatchAndSubtractMedUnderFlow(t *testing.T) {
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- newMed := fmt.Sprintf("%d", newPath.GetMed())
+ v, err := newPath.GetMed()
+ assert.Nil(t, err)
+ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed)
}
@@ -1846,6 +1853,6 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) {
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- newMed := fmt.Sprintf("%d", newPath.GetMed())
- assert.Equal(t, "0", newMed)
+ _, err := newPath.GetMed()
+ assert.NotNil(t, err)
}