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