github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/containerregistry/apply_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/testutil"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestContainerRegistryService_convertApplyRequest(t *testing.T) {
    27  	caller := testutil.SingletonAPICaller()
    28  	name := testutil.ResourceName("container-registry-service")
    29  
    30  	cases := []struct {
    31  		in     *ApplyRequest
    32  		expect *Builder
    33  	}{
    34  		{
    35  			in: &ApplyRequest{
    36  				Name:           name,
    37  				Description:    "desc",
    38  				Tags:           types.Tags{"tag1", "tag2"},
    39  				AccessLevel:    types.ContainerRegistryAccessLevels.ReadWrite,
    40  				VirtualDomain:  "container-registry.test.libsacloud.com",
    41  				SubDomainLabel: name,
    42  				Users: []*User{
    43  					{
    44  						UserName:   "user1",
    45  						Password:   "password1",
    46  						Permission: types.ContainerRegistryPermissions.ReadWrite,
    47  					},
    48  				},
    49  				SettingsHash: "aaaaaaaa",
    50  			},
    51  			expect: &Builder{
    52  				ID:             0,
    53  				Name:           name,
    54  				Description:    "desc",
    55  				Tags:           types.Tags{"tag1", "tag2"},
    56  				AccessLevel:    types.ContainerRegistryAccessLevels.ReadWrite,
    57  				VirtualDomain:  "container-registry.test.libsacloud.com",
    58  				SubDomainLabel: name,
    59  				Users: []*User{
    60  					{
    61  						UserName:   "user1",
    62  						Password:   "password1",
    63  						Permission: types.ContainerRegistryPermissions.ReadWrite,
    64  					},
    65  				},
    66  				SettingsHash: "aaaaaaaa",
    67  				Client:       sacloud.NewContainerRegistryOp(caller),
    68  			},
    69  		},
    70  	}
    71  
    72  	for _, tc := range cases {
    73  		builder, err := tc.in.Builder(caller)
    74  		require.NoError(t, err)
    75  		require.EqualValues(t, tc.expect, builder)
    76  	}
    77  }