github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/vpcrouter/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 vpcrouter 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/libsacloud/v2/sacloud" 21 "github.com/sacloud/libsacloud/v2/sacloud/types" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestVPCRouterService_convertCreateRequest(t *testing.T) { 26 cases := []struct { 27 in *CreateRequest 28 expect *ApplyRequest 29 }{ 30 { 31 in: &CreateRequest{ 32 Zone: "tk1a", 33 Name: "name", 34 Description: "desc", 35 Tags: types.Tags{"tag1", "tag2"}, 36 IconID: 101, 37 PlanID: types.VPCRouterPlans.Premium, 38 Version: 1, 39 NICSetting: &PremiumNICSetting{ 40 SwitchID: 102, 41 IPAddresses: []string{"192.168.0.101", "192.168.0.102"}, 42 VirtualIPAddress: "192.168.0.11", 43 IPAliases: []string{"192.168.0.12", "192.168.0.13"}, 44 }, 45 AdditionalNICSettings: []*AdditionalPremiumNICSetting{ 46 { 47 SwitchID: 103, 48 IPAddresses: []string{"192.168.1.101", "192.168.1.102"}, 49 VirtualIPAddress: "192.168.1.11", 50 NetworkMaskLen: 24, 51 Index: 1, 52 }, 53 }, 54 RouterSetting: &RouterSetting{ 55 VRID: 1, 56 InternetConnectionEnabled: true, 57 L2TPIPsecServer: &sacloud.VPCRouterL2TPIPsecServer{ 58 RangeStart: "192.168.0.250", 59 RangeStop: "192.168.0.254", 60 PreSharedSecret: "presharedsecret", 61 }, 62 RemoteAccessUsers: []*sacloud.VPCRouterRemoteAccessUser{ 63 { 64 UserName: "username", 65 Password: "password", 66 }, 67 }, 68 }, 69 NoWait: true, 70 BootAfterCreate: true, 71 }, 72 expect: &ApplyRequest{ 73 Zone: "tk1a", 74 Name: "name", 75 Description: "desc", 76 Tags: types.Tags{"tag1", "tag2"}, 77 IconID: 101, 78 PlanID: types.VPCRouterPlans.Premium, 79 Version: 1, 80 NICSetting: &PremiumNICSetting{ 81 SwitchID: 102, 82 IPAddresses: []string{"192.168.0.101", "192.168.0.102"}, 83 VirtualIPAddress: "192.168.0.11", 84 IPAliases: []string{"192.168.0.12", "192.168.0.13"}, 85 }, 86 AdditionalNICSettings: []AdditionalNICSettingHolder{ 87 &AdditionalPremiumNICSetting{ 88 SwitchID: 103, 89 IPAddresses: []string{"192.168.1.101", "192.168.1.102"}, 90 VirtualIPAddress: "192.168.1.11", 91 NetworkMaskLen: 24, 92 Index: 1, 93 }, 94 }, 95 RouterSetting: &RouterSetting{ 96 VRID: 1, 97 InternetConnectionEnabled: true, 98 L2TPIPsecServer: &sacloud.VPCRouterL2TPIPsecServer{ 99 RangeStart: "192.168.0.250", 100 RangeStop: "192.168.0.254", 101 PreSharedSecret: "presharedsecret", 102 }, 103 RemoteAccessUsers: []*sacloud.VPCRouterRemoteAccessUser{ 104 { 105 UserName: "username", 106 Password: "password", 107 }, 108 }, 109 }, 110 NoWait: true, 111 BootAfterCreate: true, 112 }, 113 }, 114 } 115 116 for _, tc := range cases { 117 require.EqualValues(t, tc.expect, tc.in.ApplyRequest()) 118 } 119 }