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