mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-11-19 20:11:36 +01:00
fix(bgp_policies_test.go): actually test policy
Previously, this section was commented out and full testing to ensure that the policies matched was not performed. Now the unit tests are more complete and actually test that the expected policies are present.
This commit is contained in:
parent
fa7bcdeb06
commit
ae9d0e31e8
@ -867,14 +867,13 @@ func Test_AddPolicies(t *testing.T) {
|
|||||||
t.Fatalf("error validating defined sets: %v", err)
|
t.Fatalf("error validating defined sets: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPolicies(t, testcase, gobgpapi.PolicyDirection_EXPORT, gobgpapi.RouteAction_REJECT, testcase.exportPolicyStatements)
|
checkPolicies(t, testcase, gobgpapi.PolicyDirection_EXPORT, testcase.exportPolicyStatements)
|
||||||
checkPolicies(t, testcase, gobgpapi.PolicyDirection_IMPORT, gobgpapi.RouteAction_ACCEPT, testcase.importPolicyStatements)
|
checkPolicies(t, testcase, gobgpapi.PolicyDirection_IMPORT, testcase.importPolicyStatements)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpapi.PolicyDirection, defaultPolicy gobgpapi.RouteAction,
|
func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpapi.PolicyDirection, policyStatements []*gobgpapi.Statement) {
|
||||||
policyStatements []*gobgpapi.Statement) {
|
|
||||||
policyExists := false
|
policyExists := false
|
||||||
|
|
||||||
var direction string
|
var direction string
|
||||||
@ -911,15 +910,15 @@ func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpap
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !policyAssignmentExists {
|
if !policyAssignmentExists {
|
||||||
t.Errorf("export policy assignment 'kube_router_%v' was not added", direction)
|
t.Errorf("%s policy assignment 'kube_router_%s' was not added", direction, direction)
|
||||||
}
|
}
|
||||||
/*
|
err = testcase.nrc.bgpServer.ListPolicy(context.Background(), &gobgpapi.ListPolicyRequest{Name: fmt.Sprintf("kube_router_%s", direction)}, func(foundPolicy *gobgpapi.Policy) {
|
||||||
statements := testcase.nrc.bgpServer.GetStatement()
|
|
||||||
for _, expectedStatement := range policyStatements {
|
for _, expectedStatement := range policyStatements {
|
||||||
found := false
|
found := false
|
||||||
for _, statement := range statements {
|
for _, statement := range foundPolicy.Statements {
|
||||||
if reflect.DeepEqual(statement, expectedStatement) {
|
if reflect.DeepEqual(statement, expectedStatement) {
|
||||||
found = true
|
found = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,5 +926,8 @@ func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpap
|
|||||||
t.Errorf("statement %v not found", expectedStatement)
|
t.Errorf("statement %v not found", expectedStatement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected to find a policy, but none were returned")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user