Skip to content

Commit

Permalink
[enhance] return empty list instead of nil in api list loadbalancer
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 22, 2024
1 parent 0cde8bb commit 645718a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions test/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 7 additions & 1 deletion vngcloud/services/loadbalancer/v2/loadbalancer_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 645718a

Please sign in to comment.