github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/database/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 database
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestDatabaseService_convertCreateRequest(t *testing.T) {
    25  	cases := []struct {
    26  		in     *CreateRequest
    27  		expect *ApplyRequest
    28  	}{
    29  		{
    30  			in:     &CreateRequest{},
    31  			expect: &ApplyRequest{},
    32  		},
    33  		{
    34  			in: &CreateRequest{
    35  				Zone:                  "is1a",
    36  				Name:                  "name",
    37  				Description:           "description",
    38  				Tags:                  types.Tags{"tag1", "tag2"},
    39  				IconID:                types.ID(1),
    40  				PlanID:                types.DatabasePlans.DB30GB,
    41  				SwitchID:              types.ID(1),
    42  				IPAddresses:           []string{"192.168.0.101"},
    43  				NetworkMaskLen:        24,
    44  				DefaultRoute:          "192.168.0.1",
    45  				Port:                  5432,
    46  				SourceNetwork:         []string{"192.168.0.0/24"},
    47  				DatabaseType:          types.RDBMSTypesPostgreSQL.String(),
    48  				Username:              "default",
    49  				Password:              "password1",
    50  				EnableReplication:     true,
    51  				ReplicaUserPassword:   "password2",
    52  				EnableWebUI:           true,
    53  				EnableBackup:          true,
    54  				BackupWeekdays:        []types.EBackupSpanWeekday{types.BackupSpanWeekdays.Monday},
    55  				BackupStartTimeHour:   10,
    56  				BackupStartTimeMinute: 0,
    57  				NoWait:                true,
    58  			},
    59  			expect: &ApplyRequest{
    60  				ID:                    0,
    61  				Zone:                  "is1a",
    62  				Name:                  "name",
    63  				Description:           "description",
    64  				Tags:                  types.Tags{"tag1", "tag2"},
    65  				IconID:                types.ID(1),
    66  				PlanID:                types.DatabasePlans.DB30GB,
    67  				SwitchID:              types.ID(1),
    68  				IPAddresses:           []string{"192.168.0.101"},
    69  				NetworkMaskLen:        24,
    70  				DefaultRoute:          "192.168.0.1",
    71  				Port:                  5432,
    72  				SourceNetwork:         []string{"192.168.0.0/24"},
    73  				DatabaseType:          types.RDBMSTypesPostgreSQL.String(),
    74  				Username:              "default",
    75  				Password:              "password1",
    76  				EnableReplication:     true,
    77  				ReplicaUserPassword:   "password2",
    78  				EnableWebUI:           true,
    79  				EnableBackup:          true,
    80  				BackupWeekdays:        []types.EBackupSpanWeekday{types.BackupSpanWeekdays.Monday},
    81  				BackupStartTimeHour:   10,
    82  				BackupStartTimeMinute: 0,
    83  				NoWait:                true,
    84  			},
    85  		},
    86  	}
    87  
    88  	for _, tc := range cases {
    89  		require.EqualValues(t, tc.expect, tc.in.ApplyRequest())
    90  	}
    91  }