github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/containerregistry/update_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 "context" 19 "testing" 20 21 "github.com/sacloud/libsacloud/v2/sacloud" 22 "github.com/sacloud/libsacloud/v2/sacloud/pointer" 23 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 24 "github.com/sacloud/libsacloud/v2/sacloud/types" 25 "github.com/stretchr/testify/require" 26 ) 27 28 func TestContainerRegistryService_convertUpdateRequest(t *testing.T) { 29 caller := testutil.SingletonAPICaller() 30 name := testutil.ResourceName("container-registry-service") 31 32 // setup 33 svc := New(caller) 34 current, err := svc.Create(&CreateRequest{ 35 Name: name, 36 Description: "desc", 37 Tags: types.Tags{"tag1", "tag2"}, 38 AccessLevel: types.ContainerRegistryAccessLevels.ReadWrite, 39 VirtualDomain: "container-registry.test.libsacloud.com", 40 SubDomainLabel: name, 41 Users: []*User{ 42 { 43 UserName: "username", 44 Password: "password", 45 Permission: types.ContainerRegistryPermissions.ReadWrite, 46 }, 47 }, 48 }) 49 if err != nil { 50 t.Fatal(err) 51 } 52 53 defer func() { 54 sacloud.NewContainerRegistryOp(caller).Delete(context.Background(), current.ID) // nolint 55 }() 56 57 // test 58 cases := []struct { 59 in *UpdateRequest 60 expect *ApplyRequest 61 }{ 62 { 63 in: &UpdateRequest{ 64 ID: current.ID, 65 Name: pointer.NewString(current.Name + "-upd"), 66 AccessLevel: &types.ContainerRegistryAccessLevels.ReadOnly, 67 VirtualDomain: pointer.NewString("updated.container-registry.test.libsacloud.com"), 68 Users: nil, 69 SettingsHash: "aaaaa", 70 }, 71 expect: &ApplyRequest{ 72 ID: current.ID, 73 Name: current.Name + "-upd", 74 Description: current.Description, 75 Tags: current.Tags, 76 IconID: current.IconID, 77 AccessLevel: types.ContainerRegistryAccessLevels.ReadOnly, 78 VirtualDomain: "updated.container-registry.test.libsacloud.com", 79 SubDomainLabel: current.SubDomainLabel, 80 Users: []*User{ 81 { 82 UserName: "username", 83 Password: "", // Usersを指定しなかった場合のパスワードは常に空となる 84 Permission: types.ContainerRegistryPermissions.ReadWrite, 85 }, 86 }, 87 SettingsHash: "aaaaa", 88 }, 89 }, 90 } 91 92 for _, tc := range cases { 93 req, err := tc.in.ApplyRequest(context.Background(), caller) 94 require.NoError(t, err) 95 require.EqualValues(t, tc.expect, req) 96 } 97 }