github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/enhanceddb/service_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  	"testing"
    19  
    20  	"github.com/sacloud/libsacloud/v2/sacloud"
    21  	"github.com/sacloud/libsacloud/v2/sacloud/pointer"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/testutil"
    23  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    24  )
    25  
    26  func TestEnhancedDBService_CRUD(t *testing.T) {
    27  	svc := New(testutil.SingletonAPICaller())
    28  	name := testutil.ResourceName("container-registry")
    29  	dbName := testutil.RandomName(10, testutil.CharSetAlpha)
    30  	password := testutil.RandomName(16, testutil.CharSetAlpha)
    31  
    32  	testutil.RunCRUD(t, &testutil.CRUDTestCase{
    33  		Parallel:           true,
    34  		PreCheck:           nil,
    35  		SetupAPICallerFunc: testutil.SingletonAPICaller,
    36  		Setup:              nil,
    37  		Create: &testutil.CRUDTestFunc{
    38  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    39  				return svc.Create(&CreateRequest{
    40  					Name:         name,
    41  					Description:  "test",
    42  					Tags:         types.Tags{"tag1", "tag2"},
    43  					DatabaseName: dbName,
    44  					Password:     password,
    45  				})
    46  			},
    47  		},
    48  		Read: &testutil.CRUDTestFunc{
    49  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    50  				return svc.Read(&ReadRequest{ID: ctx.ID})
    51  			},
    52  		},
    53  		Updates: []*testutil.CRUDTestFunc{
    54  			{
    55  				Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    56  					return svc.Update(&UpdateRequest{
    57  						ID:          ctx.ID,
    58  						Name:        pointer.NewString(name + "-upd"),
    59  						Description: pointer.NewString("test-upd"),
    60  						Tags:        pointer.NewTags(types.Tags{"tag1-upd", "tag2-upd"}),
    61  						Password:    password,
    62  					})
    63  				},
    64  			},
    65  		},
    66  		Shutdown: nil,
    67  		Delete: &testutil.CRUDTestDeleteFunc{
    68  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error {
    69  				return svc.Delete(&DeleteRequest{ID: ctx.ID})
    70  			},
    71  		},
    72  		Cleanup: nil,
    73  	})
    74  }