From 645718ae8d8af7cefcc7a3f6232252be31503223 Mon Sep 17 00:00:00 2001 From: "Cuong. Duong Manh" Date: Sat, 22 Jun 2024 14:30:49 +0700 Subject: [PATCH] [enhance] return empty list instead of nil in api list loadbalancer --- test/lb_test.go | 18 ++++++++++++++++++ .../loadbalancer/v2/loadbalancer_response.go | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/test/lb_test.go b/test/lb_test.go index 9424bc6..aadf125 100644 --- a/test/lb_test.go +++ b/test/lb_test.go @@ -199,6 +199,24 @@ func TestListLoadBalancer(t *ltesting.T) { t.Log("PASS") } +func TestListLoadBalancerByTagsSuccess(t *ltesting.T) { + vngcloud := validSdkConfig() + opt := lslbv2.NewListLoadBalancersRequest(1, 10). + WithTags("vks-owned-cluster", "hcm03a_user-11412_k8s-a3c03d8e-344c-4a1e-98e0-6d9999ac8077") + + lbs, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ListLoadBalancers(opt) + if sdkerr != nil { + t.Fatalf("Expect nil but got %+v", sdkerr) + } + + if lbs == nil { + t.Fatalf("Expect not nil but got nil") + } + + t.Log("Result: ", lbs) + t.Log("PASS") +} + func TestCreatePoolWithoutMembersSuccess(t *ltesting.T) { vngcloud := validSdkHannibalConfig() opt := lslbv2.NewCreatePoolRequest("cuongdm3-test-pool-7", lslbv2.PoolProtocolTCP). diff --git a/vngcloud/services/loadbalancer/v2/loadbalancer_response.go b/vngcloud/services/loadbalancer/v2/loadbalancer_response.go index 59486c0..a55c7ef 100644 --- a/vngcloud/services/loadbalancer/v2/loadbalancer_response.go +++ b/vngcloud/services/loadbalancer/v2/loadbalancer_response.go @@ -63,7 +63,13 @@ func (s *GetLoadBalancerByIdResponse) ToEntityLoadBalancer() *lsentity.LoadBalan func (s *ListLoadBalancersResponse) ToEntityListLoadBalancers() *lsentity.ListLoadBalancers { if s == nil || s.ListData == nil || len(s.ListData) < 1 { - return nil + return &lsentity.ListLoadBalancers{ + Page: 0, + PageSize: 0, + TotalPage: 0, + TotalItem: 0, + Items: make([]*lsentity.LoadBalancer, 0), + } } result := &lsentity.ListLoadBalancers{