Skip to content

Commit

Permalink
fix(bgp_policies_test.go): actually test policy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aauren committed May 17, 2021
1 parent fa7bcde commit ae9d0e3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/controllers/routing/bgp_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,13 @@ func Test_AddPolicies(t *testing.T) {
t.Fatalf("error validating defined sets: %v", err)
}

checkPolicies(t, testcase, gobgpapi.PolicyDirection_EXPORT, gobgpapi.RouteAction_REJECT, testcase.exportPolicyStatements)
checkPolicies(t, testcase, gobgpapi.PolicyDirection_IMPORT, gobgpapi.RouteAction_ACCEPT, testcase.importPolicyStatements)
checkPolicies(t, testcase, gobgpapi.PolicyDirection_EXPORT, testcase.exportPolicyStatements)
checkPolicies(t, testcase, gobgpapi.PolicyDirection_IMPORT, testcase.importPolicyStatements)
})
}
}

func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpapi.PolicyDirection, defaultPolicy gobgpapi.RouteAction,
policyStatements []*gobgpapi.Statement) {
func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpapi.PolicyDirection, policyStatements []*gobgpapi.Statement) {
policyExists := false

var direction string
Expand Down Expand Up @@ -911,21 +910,24 @@ func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpap
}

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)
}
/*
statements := testcase.nrc.bgpServer.GetStatement()
err = testcase.nrc.bgpServer.ListPolicy(context.Background(), &gobgpapi.ListPolicyRequest{Name: fmt.Sprintf("kube_router_%s", direction)}, func(foundPolicy *gobgpapi.Policy) {
for _, expectedStatement := range policyStatements {
found := false
for _, statement := range statements {
for _, statement := range foundPolicy.Statements {
if reflect.DeepEqual(statement, expectedStatement) {
found = true
break
}
}

if !found {
t.Errorf("statement %v not found", expectedStatement)
}
}
*/
})
if err != nil {
t.Fatalf("expected to find a policy, but none were returned")
}
}

0 comments on commit ae9d0e3

Please sign in to comment.