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