github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/server/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 server
    16  
    17  import (
    18  	"testing"
    19  
    20  	diskService "github.com/sacloud/libsacloud/v2/helper/service/disk"
    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 TestServerService_convertCreateRequest(t *testing.T) {
    27  	zone := testutil.TestZone()
    28  	name := testutil.ResourceName("service-server-create")
    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  				IconID:          101,
    41  				CPU:             22,
    42  				MemoryGB:        4,
    43  				Commitment:      types.Commitments.DedicatedCPU,
    44  				Generation:      types.PlanGenerations.Default,
    45  				InterfaceDriver: types.InterfaceDrivers.VirtIO,
    46  				BootAfterCreate: true,
    47  				CDROMID:         102,
    48  				PrivateHostID:   103,
    49  				NetworkInterfaces: []*NetworkInterface{
    50  					{Upstream: "shared", PacketFilterID: 104},
    51  					{Upstream: "105", UserIPAddress: "192.168.0.1"},
    52  				},
    53  				Disks: []*diskService.ApplyRequest{
    54  					{
    55  						Zone:        zone,
    56  						ID:          201,
    57  						Name:        name,
    58  						Description: "desc",
    59  						DiskPlanID:  types.DiskPlans.SSD,
    60  						Connection:  types.DiskConnections.VirtIO,
    61  						SizeGB:      20,
    62  						NoWait:      true,
    63  					},
    64  				},
    65  				NoWait: true,
    66  			},
    67  			expect: &ApplyRequest{
    68  				Zone:            zone,
    69  				Name:            name,
    70  				Description:     "desc",
    71  				Tags:            types.Tags{"tag1", "tag2"},
    72  				IconID:          101,
    73  				CPU:             22,
    74  				MemoryGB:        4,
    75  				GPU:             0,
    76  				Commitment:      types.Commitments.DedicatedCPU,
    77  				Generation:      types.PlanGenerations.Default,
    78  				InterfaceDriver: types.InterfaceDrivers.VirtIO,
    79  				BootAfterCreate: true,
    80  				CDROMID:         102,
    81  				PrivateHostID:   103,
    82  				NetworkInterfaces: []*NetworkInterface{
    83  					{Upstream: "shared", PacketFilterID: 104},
    84  					{Upstream: "105", UserIPAddress: "192.168.0.1"},
    85  				},
    86  				Disks: []*diskService.ApplyRequest{
    87  					{
    88  						Zone:        zone,
    89  						ID:          201,
    90  						Name:        name,
    91  						Description: "desc",
    92  						DiskPlanID:  types.DiskPlans.SSD,
    93  						Connection:  types.DiskConnections.VirtIO,
    94  						SizeGB:      20,
    95  						NoWait:      true,
    96  					},
    97  				},
    98  				NoWait: true,
    99  			},
   100  		},
   101  	}
   102  
   103  	for _, tc := range cases {
   104  		require.EqualValues(t, tc.expect, tc.in.ApplyRequest())
   105  	}
   106  }