github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/mobilegateway/builder_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 "testing" 19 "time" 20 21 "github.com/sacloud/libsacloud/v2/helper/builder" 22 23 "github.com/sacloud/libsacloud/v2/sacloud" 24 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 25 "github.com/sacloud/libsacloud/v2/sacloud/types" 26 ) 27 28 func getSetupOption() *builder.RetryableSetupParameter { 29 if testutil.IsAccTest() { 30 return nil 31 } 32 return &builder.RetryableSetupParameter{ 33 DeleteRetryInterval: 10 * time.Millisecond, 34 ProvisioningRetryInterval: 10 * time.Millisecond, 35 PollingInterval: 10 * time.Millisecond, 36 NICUpdateWaitDuration: 10 * time.Millisecond, 37 } 38 } 39 40 func TestMobileGatewayBuilder_Build(t *testing.T) { 41 var switchID types.ID 42 var testZone = testutil.TestZone() 43 44 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 45 SetupAPICallerFunc: func() sacloud.APICaller { 46 return testutil.SingletonAPICaller() 47 }, 48 Parallel: true, 49 IgnoreStartupWait: true, 50 Setup: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 51 swOp := sacloud.NewSwitchOp(caller) 52 53 sw, err := swOp.Create(ctx, testZone, &sacloud.SwitchCreateRequest{ 54 Name: testutil.ResourceName("mobile-gateway-builder"), 55 }) 56 if err != nil { 57 return err 58 } 59 switchID = sw.ID 60 return nil 61 }, 62 Create: &testutil.CRUDTestFunc{ 63 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 64 builder := &Builder{ 65 Name: testutil.ResourceName("mobile-gateway-builder"), 66 Description: "description", 67 Tags: types.Tags{"tag1", "tag2"}, 68 PrivateInterface: &PrivateInterfaceSetting{ 69 SwitchID: switchID, 70 IPAddress: "192.168.0.1", 71 NetworkMaskLen: 24, 72 }, 73 StaticRoutes: []*sacloud.MobileGatewayStaticRoute{ 74 { 75 Prefix: "192.168.1.0/24", 76 NextHop: "192.168.0.1", 77 }, 78 { 79 Prefix: "192.168.2.0/24", 80 NextHop: "192.168.0.1", 81 }, 82 }, 83 SIMs: nil, 84 SIMRoutes: nil, 85 InternetConnectionEnabled: true, 86 InterDeviceCommunicationEnabled: true, 87 DNS: &sacloud.MobileGatewayDNSSetting{ 88 DNS1: "1.1.1.1", 89 DNS2: "2.2.2.2", 90 }, 91 TrafficConfig: &sacloud.MobileGatewayTrafficControl{ 92 TrafficQuotaInMB: 1024, 93 BandWidthLimitInKbps: 128, 94 EmailNotifyEnabled: true, 95 AutoTrafficShaping: true, 96 }, 97 SetupOptions: getSetupOption(), 98 Client: NewAPIClient(caller), 99 } 100 return builder.Build(ctx, testZone) 101 }, 102 }, 103 Read: &testutil.CRUDTestFunc{ 104 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 105 mgwOp := sacloud.NewMobileGatewayOp(caller) 106 return mgwOp.Read(ctx, testZone, ctx.ID) 107 }, 108 CheckFunc: func(t testutil.TestT, ctx *testutil.CRUDTestContext, value interface{}) error { 109 mgw := value.(*sacloud.MobileGateway) 110 return testutil.DoAsserts( 111 testutil.AssertNotNilFunc(t, mgw, "MobileGateway"), 112 testutil.AssertLenFunc(t, mgw.InterfaceSettings, 1, "MobileGateway.InterfaceSettings"), 113 ) 114 }, 115 }, 116 Delete: &testutil.CRUDTestDeleteFunc{ 117 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 118 mgwOp := sacloud.NewMobileGatewayOp(caller) 119 return mgwOp.Delete(ctx, testZone, ctx.ID) 120 }, 121 }, 122 Cleanup: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 123 swOp := sacloud.NewSwitchOp(caller) 124 return swOp.Delete(ctx, testZone, switchID) 125 }, 126 }) 127 }