github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/privatehost/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 privatehost 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 TestPrivateHostService_CRUD(t *testing.T) { 27 svc := New(testutil.SingletonAPICaller()) 28 name := testutil.ResourceName("private-host") 29 zone := testutil.TestZone() 30 31 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 32 Parallel: true, 33 PreCheck: nil, 34 SetupAPICallerFunc: testutil.SingletonAPICaller, 35 IgnoreStartupWait: true, 36 Create: &testutil.CRUDTestFunc{ 37 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 38 return svc.Create(&CreateRequest{ 39 Name: name, 40 Description: "test", 41 Tags: types.Tags{"tag1", "tag2"}, 42 Zone: zone, 43 Class: types.PrivateHostClassDynamic, 44 }) 45 }, 46 }, 47 Read: &testutil.CRUDTestFunc{ 48 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 49 return svc.Read(&ReadRequest{ID: ctx.ID, Zone: zone}) 50 }, 51 }, 52 Updates: []*testutil.CRUDTestFunc{ 53 { 54 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 55 return svc.Update(&UpdateRequest{ 56 ID: ctx.ID, 57 Name: pointer.NewString(name + "-upd"), 58 Description: pointer.NewString("test-upd"), 59 Zone: zone, 60 }) 61 }, 62 }, 63 }, 64 Delete: &testutil.CRUDTestDeleteFunc{ 65 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error { 66 return svc.Delete(&DeleteRequest{ID: ctx.ID, Zone: zone}) 67 }, 68 }, 69 Cleanup: nil, 70 }) 71 }