diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-13 10:29:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-13 14:06:55 +0900 |
commit | 99b272438618c33fecc74ae8514c6a10f3de8f8f (patch) | |
tree | aa8ea9e10dec9811d5f09d46d8c113dc30a7ec00 /pkg/server/server_test.go | |
parent | 91dd60676b9da9a0c39e45f0a656ac2919b0d558 (diff) |
server: change List API design
https://github.com/osrg/gobgp/issues/1763#issuecomment-437594975
Follow Chris's proposal; more consistent with gRPC streaming API.
Also supports context properly.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/server/server_test.go')
-rw-r--r-- | pkg/server/server_test.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 27f56353..c8975e41 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -78,9 +78,10 @@ func TestModPolicyAssign(t *testing.T) { err = s.AddPolicyAssignment(context.Background(), &api.AddPolicyAssignmentRequest{Assignment: r}) assert.Nil(err) - ps, err := s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ + var ps []*api.PolicyAssignment + err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ Name: table.GLOBAL_RIB_NAME, - Direction: api.PolicyDirection_IMPORT}) + Direction: api.PolicyDirection_IMPORT}, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Nil(err) assert.Equal(len(ps[0].Policies), 3) @@ -91,14 +92,16 @@ func TestModPolicyAssign(t *testing.T) { err = s.DeletePolicyAssignment(context.Background(), &api.DeletePolicyAssignmentRequest{Assignment: r}) assert.Nil(err) - ps, _ = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ + ps = []*api.PolicyAssignment{} + s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ Name: table.GLOBAL_RIB_NAME, - Direction: api.PolicyDirection_IMPORT}) + Direction: api.PolicyDirection_IMPORT}, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Equal(len(ps[0].Policies), 2) - ps, _ = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ + ps = []*api.PolicyAssignment{} + s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ Name: table.GLOBAL_RIB_NAME, - }) + }, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Equal(len(ps), 2) } @@ -145,19 +148,22 @@ func TestListPolicyAssignment(t *testing.T) { assert.Nil(err) } - ps, err := s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ + ps := []*api.PolicyAssignment{} + err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ Name: table.GLOBAL_RIB_NAME, - }) + }, func(p *api.PolicyAssignment) { ps = append(ps, p) }) assert.Nil(err) assert.Equal(len(ps), 0) - ps, err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{}) + 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) - ps, err = s.ListPolicyAssignment(context.Background(), &api.ListPolicyAssignmentRequest{ + 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) } |