From 22d745fcf591c2a14204598cb2b00877c7a9e3c6 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 20 Oct 2020 14:38:03 +0900 Subject: server: fix ListPolicyAssignment to handle empty policy fix ListPolicyAssignment() return an assignment response even if the response doesn't have any policy. The assignment has default action policy so it's useful without any policy. Signed-off-by: FUJITA Tomonori --- pkg/server/server.go | 3 --- pkg/server/server_test.go | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 1b49880d..ef8bd3c8 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -3492,9 +3492,6 @@ func (s *BgpServer) ListPolicyAssignment(ctx context.Context, r *api.ListPolicyA if err != nil { return err } - if len(policies) == 0 { - continue - } t := &table.PolicyAssignment{ Name: name, Type: dir, diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 34e9be1f..6f70f38a 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -194,19 +194,19 @@ func TestListPolicyAssignment(t *testing.T) { Name: table.GLOBAL_RIB_NAME, }, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Nil(err) - assert.Equal(len(ps), 0) + assert.Equal(2, len(ps)) ps = []*api.PolicyAssignment{} err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{}, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Nil(err) - assert.Equal(len(ps), 3) + assert.Equal(8, len(ps)) ps = []*api.PolicyAssignment{} err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ Direction: api.PolicyDirection_EXPORT, }, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Nil(err) - assert.Equal(len(ps), 0) + assert.Equal(4, len(ps)) } func TestListPathEnableFiltered(test *testing.T) { -- cgit v1.2.3