github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/localrouter/service_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 localrouter 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/libsacloud/v2/sacloud" 21 "github.com/sacloud/libsacloud/v2/sacloud/pointer" 22 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 23 "github.com/sacloud/libsacloud/v2/sacloud/types" 24 ) 25 26 func TestLocalRouterService_CRUD(t *testing.T) { 27 svc := New(testutil.SingletonAPICaller()) 28 name := testutil.ResourceName("local-router") 29 30 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 31 Parallel: true, 32 PreCheck: nil, 33 SetupAPICallerFunc: testutil.SingletonAPICaller, 34 Setup: nil, 35 Create: &testutil.CRUDTestFunc{ 36 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 37 return svc.Create(&CreateRequest{ 38 Name: name, 39 Description: "test", 40 Tags: types.Tags{"tag1", "tag2"}, 41 }) 42 }, 43 }, 44 Read: &testutil.CRUDTestFunc{ 45 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 46 return svc.Read(&ReadRequest{ID: ctx.ID}) 47 }, 48 }, 49 Updates: []*testutil.CRUDTestFunc{ 50 { 51 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 52 return svc.Update(&UpdateRequest{ 53 ID: ctx.ID, 54 Name: pointer.NewString(name + "-upd"), 55 Description: pointer.NewString("test-upd"), 56 }) 57 }, 58 }, 59 }, 60 Shutdown: nil, 61 Delete: &testutil.CRUDTestDeleteFunc{ 62 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error { 63 return svc.Delete(&DeleteRequest{ID: ctx.ID}) 64 }, 65 }, 66 Cleanup: nil, 67 }) 68 }