github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/containerregistry/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 containerregistry 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 TestContainerRegistryService_CRUD(t *testing.T) { 27 svc := New(testutil.SingletonAPICaller()) 28 name := testutil.ResourceName("container-registry") 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 AccessLevel: types.ContainerRegistryAccessLevels.ReadOnly, 42 VirtualDomain: name + ".usacloud.jp", 43 SubDomainLabel: name, 44 Users: []*User{ 45 { 46 UserName: "user1", 47 Password: "password1", 48 Permission: types.ContainerRegistryPermissions.ReadOnly, 49 }, 50 { 51 UserName: "user2", 52 Password: "password2", 53 Permission: types.ContainerRegistryPermissions.ReadOnly, 54 }, 55 }, 56 }) 57 }, 58 }, 59 Read: &testutil.CRUDTestFunc{ 60 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 61 return svc.Read(&ReadRequest{ID: ctx.ID}) 62 }, 63 }, 64 Updates: []*testutil.CRUDTestFunc{ 65 { 66 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) { 67 return svc.Update(&UpdateRequest{ 68 ID: ctx.ID, 69 Name: pointer.NewString(name + "-upd"), 70 Description: pointer.NewString("test-upd"), 71 Tags: pointer.NewTags(types.Tags{"tag1-upd", "tag2-upd"}), 72 AccessLevel: &types.ContainerRegistryAccessLevels.ReadOnly, 73 VirtualDomain: pointer.NewString(name + "-upd.usacloud.jp"), 74 Users: &[]*User{ 75 { 76 UserName: "user1", 77 Password: "password1", 78 Permission: types.ContainerRegistryPermissions.ReadWrite, 79 }, 80 { 81 UserName: "user3", 82 Password: "password3", 83 Permission: types.ContainerRegistryPermissions.ReadOnly, 84 }, 85 }, 86 }) 87 }, 88 }, 89 }, 90 Shutdown: nil, 91 Delete: &testutil.CRUDTestDeleteFunc{ 92 Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error { 93 return svc.Delete(&DeleteRequest{ID: ctx.ID}) 94 }, 95 }, 96 Cleanup: nil, 97 }) 98 }