github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/registry/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 registry 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/libsacloud/v2/sacloud" 21 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 22 "github.com/sacloud/libsacloud/v2/sacloud/types" 23 ) 24 25 func TestBuilder_Build(t *testing.T) { 26 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 27 SetupAPICallerFunc: func() sacloud.APICaller { 28 return testutil.SingletonAPICaller() 29 }, 30 Parallel: true, 31 IgnoreStartupWait: true, 32 Create: &testutil.CRUDTestFunc{ 33 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 34 builder := &Builder{ 35 Name: testutil.ResourceName("container-registry-builder"), 36 Description: "description", 37 Tags: types.Tags{"tag1", "tag2"}, 38 AccessLevel: types.ContainerRegistryAccessLevels.None, 39 SubDomainLabel: testutil.RandomName(60, testutil.CharSetAlpha), 40 Users: []*User{ 41 { 42 UserName: "user1", 43 Password: "password", 44 Permission: types.ContainerRegistryPermissions.ReadWrite, 45 }, 46 { 47 UserName: "user2", 48 Password: "password", 49 Permission: types.ContainerRegistryPermissions.ReadOnly, 50 }, 51 }, 52 Client: NewAPIClient(caller), 53 } 54 return builder.Build(ctx) 55 }, 56 }, 57 Read: &testutil.CRUDTestFunc{ 58 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) (interface{}, error) { 59 regOp := sacloud.NewContainerRegistryOp(caller) 60 return regOp.Read(ctx, ctx.ID) 61 }, 62 CheckFunc: func(t testutil.TestT, ctx *testutil.CRUDTestContext, value interface{}) error { 63 reg := value.(*sacloud.ContainerRegistry) 64 return testutil.DoAsserts( 65 testutil.AssertNotNilFunc(t, reg, "ContainerRegistry"), 66 ) 67 }, 68 }, 69 Delete: &testutil.CRUDTestDeleteFunc{ 70 Func: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error { 71 regOp := sacloud.NewContainerRegistryOp(caller) 72 return regOp.Delete(ctx, ctx.ID) 73 }, 74 }, 75 }) 76 }