github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/mobilegateway/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 mobilegateway
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/sacloud/libsacloud/v2/sacloud"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/testutil"
    23  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    24  	"github.com/stretchr/testify/require"
    25  )
    26  
    27  func TestMobileGatewayService_convertCreateRequest(t *testing.T) {
    28  	ctx := context.Background()
    29  	name := testutil.ResourceName("mobile-gateway-service-create")
    30  	zone := testutil.TestZone()
    31  	caller := testutil.SingletonAPICaller()
    32  
    33  	// setup
    34  	swOp := sacloud.NewSwitchOp(caller)
    35  	sw, err := swOp.Create(ctx, zone, &sacloud.SwitchCreateRequest{Name: name})
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	defer func() {
    40  		swOp.Delete(ctx, zone, sw.ID) // nolint
    41  	}()
    42  
    43  	// test
    44  	cases := []struct {
    45  		in     *CreateRequest
    46  		expect *ApplyRequest
    47  	}{
    48  		{
    49  			in: &CreateRequest{
    50  				Zone:        zone,
    51  				Name:        name,
    52  				Description: "description",
    53  				Tags:        types.Tags{"tag1", "tag2"},
    54  				PrivateInterface: &PrivateInterfaceSetting{
    55  					SwitchID:       sw.ID,
    56  					IPAddress:      "192.168.0.1",
    57  					NetworkMaskLen: 24,
    58  				},
    59  				StaticRoutes: []*sacloud.MobileGatewayStaticRoute{
    60  					{
    61  						Prefix:  "192.168.1.0/24",
    62  						NextHop: "192.168.0.2",
    63  					},
    64  				},
    65  				InternetConnectionEnabled:       true,
    66  				InterDeviceCommunicationEnabled: true,
    67  				DNS: &DNSSetting{
    68  					DNS1: "8.8.8.8",
    69  					DNS2: "8.8.4.4",
    70  				},
    71  				SIMs: nil,
    72  				TrafficConfig: &TrafficConfig{
    73  					TrafficQuotaInMB:     10,
    74  					BandWidthLimitInKbps: 128,
    75  					EmailNotifyEnabled:   true,
    76  					AutoTrafficShaping:   true,
    77  				},
    78  				NoWait:          false,
    79  				BootAfterCreate: true,
    80  			},
    81  			expect: &ApplyRequest{
    82  				Zone:        zone,
    83  				Name:        name,
    84  				Description: "description",
    85  				Tags:        types.Tags{"tag1", "tag2"},
    86  				PrivateInterface: &PrivateInterfaceSetting{
    87  					SwitchID:       sw.ID,
    88  					IPAddress:      "192.168.0.1",
    89  					NetworkMaskLen: 24,
    90  				},
    91  				StaticRoutes: []*sacloud.MobileGatewayStaticRoute{
    92  					{
    93  						Prefix:  "192.168.1.0/24",
    94  						NextHop: "192.168.0.2",
    95  					},
    96  				},
    97  				InternetConnectionEnabled:       true,
    98  				InterDeviceCommunicationEnabled: true,
    99  				DNS: &DNSSetting{
   100  					DNS1: "8.8.8.8",
   101  					DNS2: "8.8.4.4",
   102  				},
   103  				SIMs: nil,
   104  				TrafficConfig: &TrafficConfig{
   105  					TrafficQuotaInMB:     10,
   106  					BandWidthLimitInKbps: 128,
   107  					EmailNotifyEnabled:   true,
   108  					AutoTrafficShaping:   true,
   109  				},
   110  				NoWait:          false,
   111  				BootAfterCreate: true,
   112  			},
   113  		},
   114  	}
   115  
   116  	for _, tc := range cases {
   117  		require.EqualValues(t, tc.expect, tc.in.ApplyRequest())
   118  	}
   119  }