github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/archive/standard_archive_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 archive 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/libsacloud/v2/helper/query" 21 "github.com/sacloud/libsacloud/v2/sacloud" 22 "github.com/sacloud/libsacloud/v2/sacloud/ostype" 23 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 24 "github.com/sacloud/libsacloud/v2/sacloud/types" 25 ) 26 27 func TestStandardArchiveBuilder_Build(t *testing.T) { 28 testZone := testutil.TestZone() 29 var sourceArchive *sacloud.Archive 30 31 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 32 SetupAPICallerFunc: func() sacloud.APICaller { 33 return testutil.SingletonAPICaller() 34 }, 35 Parallel: true, 36 IgnoreStartupWait: true, 37 Setup: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 38 archiveOp := sacloud.NewArchiveOp(caller) 39 source, err := query.FindArchiveByOSType(ctx, archiveOp, testZone, ostype.CentOS) 40 if err != nil { 41 return err 42 } 43 sourceArchive = source 44 return nil 45 }, 46 Create: &testutil.CRUDTestFunc{ 47 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 48 builder := &StandardArchiveBuilder{ 49 Name: testutil.ResourceName("standard-archive-builder"), 50 Description: "description", 51 Tags: types.Tags{"tag1", "tag2"}, 52 SourceArchiveID: sourceArchive.ID, 53 Client: NewAPIClient(caller), 54 } 55 return builder.Build(ctx, testZone) 56 }, 57 }, 58 Read: &testutil.CRUDTestFunc{ 59 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 60 return sacloud.NewArchiveOp(caller).Read(ctx, testZone, ctx.ID) 61 }, 62 CheckFunc: func(t testutil.TestT, ctx *testutil.CRUDTestContext, value interface{}) error { 63 archive := value.(*sacloud.Archive) 64 return testutil.DoAsserts( 65 testutil.AssertNotNilFunc(t, archive, "Archive"), 66 ) 67 }, 68 }, 69 Delete: &testutil.CRUDTestDeleteFunc{ 70 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 71 archiveOp := sacloud.NewArchiveOp(caller) 72 73 _, err := sacloud.WaiterForReady(func() (interface{}, error) { 74 return archiveOp.Read(ctx, testZone, ctx.ID) 75 }).WaitForState(ctx) 76 if err != nil { 77 return err 78 } 79 return archiveOp.Delete(ctx, testZone, ctx.ID) 80 }, 81 }, 82 }) 83 }