github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/loadbalancer/apply_test.go (about)

     1  // Copyright 2016-2022 The Libsacloud Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package loadbalancer
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/sacloud/libsacloud/v2/sacloud"
    21  	"github.com/sacloud/libsacloud/v2/sacloud/testutil"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestLoadBalancerService_convertApplyRequest(t *testing.T) {
    27  	caller := testutil.SingletonAPICaller()
    28  	name := testutil.ResourceName("load-balancer-service")
    29  	zone := testutil.TestZone()
    30  
    31  	cases := []struct {
    32  		in     *ApplyRequest
    33  		expect *Builder
    34  	}{
    35  		{
    36  			in: &ApplyRequest{
    37  				ID:             101,
    38  				Zone:           zone,
    39  				Name:           name,
    40  				Description:    "desc",
    41  				Tags:           types.Tags{"tag1", "tag2"},
    42  				SwitchID:       102,
    43  				PlanID:         types.LoadBalancerPlans.Standard,
    44  				VRID:           10,
    45  				IPAddresses:    []string{"192.168.0.101", "192.168.0.102"},
    46  				NetworkMaskLen: 24,
    47  				DefaultRoute:   "192.168.0.1",
    48  				VirtualIPAddresses: []*sacloud.LoadBalancerVirtualIPAddress{
    49  					{
    50  						VirtualIPAddress: "192.168.0.201",
    51  						Port:             80,
    52  						DelayLoop:        10,
    53  						SorryServer:      "192.168.0.99",
    54  						Description:      "desc",
    55  						Servers: []*sacloud.LoadBalancerServer{
    56  							{
    57  								IPAddress: "192.168.0.202",
    58  								Port:      80,
    59  								Enabled:   true,
    60  								HealthCheck: &sacloud.LoadBalancerServerHealthCheck{
    61  									Protocol:     types.LoadBalancerHealthCheckProtocols.HTTP,
    62  									Path:         "/",
    63  									ResponseCode: 200,
    64  								},
    65  							},
    66  							{
    67  								IPAddress: "192.168.0.203",
    68  								Port:      80,
    69  								Enabled:   true,
    70  								HealthCheck: &sacloud.LoadBalancerServerHealthCheck{
    71  									Protocol:     types.LoadBalancerHealthCheckProtocols.HTTP,
    72  									Path:         "/",
    73  									ResponseCode: 200,
    74  								},
    75  							},
    76  						},
    77  					},
    78  				},
    79  				NoWait: true,
    80  			},
    81  			expect: &Builder{
    82  				ID:             101,
    83  				Zone:           zone,
    84  				Name:           name,
    85  				Description:    "desc",
    86  				Tags:           types.Tags{"tag1", "tag2"},
    87  				SwitchID:       102,
    88  				PlanID:         types.LoadBalancerPlans.Standard,
    89  				VRID:           10,
    90  				IPAddresses:    []string{"192.168.0.101", "192.168.0.102"},
    91  				NetworkMaskLen: 24,
    92  				DefaultRoute:   "192.168.0.1",
    93  				VirtualIPAddresses: []*sacloud.LoadBalancerVirtualIPAddress{
    94  					{
    95  						VirtualIPAddress: "192.168.0.201",
    96  						Port:             80,
    97  						DelayLoop:        10,
    98  						SorryServer:      "192.168.0.99",
    99  						Description:      "desc",
   100  						Servers: []*sacloud.LoadBalancerServer{
   101  							{
   102  								IPAddress: "192.168.0.202",
   103  								Port:      80,
   104  								Enabled:   true,
   105  								HealthCheck: &sacloud.LoadBalancerServerHealthCheck{
   106  									Protocol:     types.LoadBalancerHealthCheckProtocols.HTTP,
   107  									Path:         "/",
   108  									ResponseCode: 200,
   109  								},
   110  							},
   111  							{
   112  								IPAddress: "192.168.0.203",
   113  								Port:      80,
   114  								Enabled:   true,
   115  								HealthCheck: &sacloud.LoadBalancerServerHealthCheck{
   116  									Protocol:     types.LoadBalancerHealthCheckProtocols.HTTP,
   117  									Path:         "/",
   118  									ResponseCode: 200,
   119  								},
   120  							},
   121  						},
   122  					},
   123  				},
   124  				NoWait: true,
   125  				Client: sacloud.NewLoadBalancerOp(caller),
   126  			},
   127  		},
   128  	}
   129  
   130  	for _, tc := range cases {
   131  		builder, err := tc.in.Builder(caller)
   132  		require.NoError(t, err)
   133  		require.EqualValues(t, tc.expect, builder)
   134  	}
   135  }