From ae9d0e31e8a1a72b14f25644cf36ea8fbc01b052 Mon Sep 17 00:00:00 2001 From: Aaron U'Ren Date: Thu, 13 May 2021 10:58:44 -0500 Subject: [PATCH] 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. --- pkg/controllers/routing/bgp_policies_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/controllers/routing/bgp_policies_test.go b/pkg/controllers/routing/bgp_policies_test.go index 73ab7c10..4e36848c 100644 --- a/pkg/controllers/routing/bgp_policies_test.go +++ b/pkg/controllers/routing/bgp_policies_test.go @@ -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 @@ -911,15 +910,15 @@ 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 } } @@ -927,5 +926,8 @@ func checkPolicies(t *testing.T, testcase PolicyTestCase, gobgpDirection gobgpap t.Errorf("statement %v not found", expectedStatement) } } - */ + }) + if err != nil { + t.Fatalf("expected to find a policy, but none were returned") + } }