github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/loadbalancer/create_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_convertCreateRequest(t *testing.T) { 27 name := testutil.ResourceName("load-balancer-service") 28 zone := testutil.TestZone() 29 30 cases := []struct { 31 in *CreateRequest 32 expect *ApplyRequest 33 }{ 34 { 35 in: &CreateRequest{ 36 Zone: zone, 37 Name: name, 38 Description: "desc", 39 Tags: types.Tags{"tag1", "tag2"}, 40 SwitchID: 102, 41 PlanID: types.LoadBalancerPlans.Standard, 42 VRID: 10, 43 IPAddresses: []string{"192.168.0.101", "192.168.0.102"}, 44 NetworkMaskLen: 24, 45 DefaultRoute: "192.168.0.1", 46 VirtualIPAddresses: []*sacloud.LoadBalancerVirtualIPAddress{ 47 { 48 VirtualIPAddress: "192.168.0.201", 49 Port: 80, 50 DelayLoop: 10, 51 SorryServer: "192.168.0.99", 52 Description: "desc", 53 Servers: []*sacloud.LoadBalancerServer{ 54 { 55 IPAddress: "192.168.0.202", 56 Port: 80, 57 Enabled: true, 58 HealthCheck: &sacloud.LoadBalancerServerHealthCheck{ 59 Protocol: types.LoadBalancerHealthCheckProtocols.HTTP, 60 Path: "/", 61 ResponseCode: 200, 62 }, 63 }, 64 { 65 IPAddress: "192.168.0.203", 66 Port: 80, 67 Enabled: true, 68 HealthCheck: &sacloud.LoadBalancerServerHealthCheck{ 69 Protocol: types.LoadBalancerHealthCheckProtocols.HTTP, 70 Path: "/", 71 ResponseCode: 200, 72 }, 73 }, 74 }, 75 }, 76 }, 77 NoWait: true, 78 }, 79 expect: &ApplyRequest{ 80 Zone: zone, 81 Name: name, 82 Description: "desc", 83 Tags: types.Tags{"tag1", "tag2"}, 84 SwitchID: 102, 85 PlanID: types.LoadBalancerPlans.Standard, 86 VRID: 10, 87 IPAddresses: []string{"192.168.0.101", "192.168.0.102"}, 88 NetworkMaskLen: 24, 89 DefaultRoute: "192.168.0.1", 90 VirtualIPAddresses: []*sacloud.LoadBalancerVirtualIPAddress{ 91 { 92 VirtualIPAddress: "192.168.0.201", 93 Port: 80, 94 DelayLoop: 10, 95 SorryServer: "192.168.0.99", 96 Description: "desc", 97 Servers: []*sacloud.LoadBalancerServer{ 98 { 99 IPAddress: "192.168.0.202", 100 Port: 80, 101 Enabled: true, 102 HealthCheck: &sacloud.LoadBalancerServerHealthCheck{ 103 Protocol: types.LoadBalancerHealthCheckProtocols.HTTP, 104 Path: "/", 105 ResponseCode: 200, 106 }, 107 }, 108 { 109 IPAddress: "192.168.0.203", 110 Port: 80, 111 Enabled: true, 112 HealthCheck: &sacloud.LoadBalancerServerHealthCheck{ 113 Protocol: types.LoadBalancerHealthCheckProtocols.HTTP, 114 Path: "/", 115 ResponseCode: 200, 116 }, 117 }, 118 }, 119 }, 120 }, 121 NoWait: true, 122 }, 123 }, 124 } 125 126 for _, tc := range cases { 127 require.EqualValues(t, tc.expect, tc.in.ApplyRequest()) 128 } 129 }