github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/enhanceddb/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 enhanceddb
    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 TestEnhancedDBService_convertUpdateRequest(t *testing.T) {
    29  	caller := testutil.SingletonAPICaller()
    30  	name := testutil.ResourceName("container-registry-service")
    31  	dbName := testutil.RandomName(10, testutil.CharSetAlpha)
    32  	password := testutil.RandomName(16, testutil.CharSetAlpha)
    33  
    34  	// setup
    35  	svc := New(caller)
    36  	current, err := svc.Create(&CreateRequest{
    37  		Name:         name,
    38  		Description:  "desc",
    39  		Tags:         types.Tags{"tag1", "tag2"},
    40  		DatabaseName: dbName,
    41  		Password:     password,
    42  	})
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  
    47  	defer func() {
    48  		sacloud.NewEnhancedDBOp(caller).Delete(context.Background(), current.ID) // nolint
    49  	}()
    50  
    51  	// test
    52  	cases := []struct {
    53  		in     *UpdateRequest
    54  		expect *ApplyRequest
    55  	}{
    56  		{
    57  			in: &UpdateRequest{
    58  				ID:           current.ID,
    59  				Name:         pointer.NewString(current.Name + "-upd"),
    60  				Password:     password,
    61  				SettingsHash: "aaaaa",
    62  			},
    63  			expect: &ApplyRequest{
    64  				ID:           current.ID,
    65  				Name:         current.Name + "-upd",
    66  				Description:  current.Description,
    67  				Tags:         current.Tags,
    68  				IconID:       current.IconID,
    69  				DatabaseName: dbName,
    70  				Password:     password,
    71  				SettingsHash: "aaaaa",
    72  			},
    73  		},
    74  	}
    75  
    76  	for _, tc := range cases {
    77  		req, err := tc.in.ApplyRequest(context.Background(), caller)
    78  		require.NoError(t, err)
    79  		require.EqualValues(t, tc.expect, req)
    80  	}
    81  }