github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/nfs/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 nfs
    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 TestNFSService_CRUD(t *testing.T) {
    27  	svc := New(testutil.SingletonAPICaller())
    28  	name := testutil.ResourceName("nfs")
    29  	zone := testutil.TestZone()
    30  	var sw *sacloud.Switch
    31  
    32  	testutil.RunCRUD(t, &testutil.CRUDTestCase{
    33  		Parallel:           true,
    34  		PreCheck:           nil,
    35  		SetupAPICallerFunc: testutil.SingletonAPICaller,
    36  		Setup: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error {
    37  			s, err := sacloud.NewSwitchOp(caller).Create(ctx, zone, &sacloud.SwitchCreateRequest{Name: name})
    38  			if err != nil {
    39  				return err
    40  			}
    41  			sw = s
    42  
    43  			return err
    44  		},
    45  		Create: &testutil.CRUDTestFunc{
    46  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    47  				return svc.Create(&CreateRequest{
    48  					Name:           name,
    49  					Description:    "test",
    50  					Tags:           types.Tags{"tag1", "tag2"},
    51  					Zone:           zone,
    52  					SwitchID:       sw.ID,
    53  					Plan:           types.NFSPlans.SSD,
    54  					Size:           types.NFSSSDSizes.Size100GB,
    55  					IPAddresses:    []string{"192.168.0.11"},
    56  					NetworkMaskLen: 24,
    57  					DefaultRoute:   "192.168.0.1",
    58  				})
    59  			},
    60  		},
    61  		Read: &testutil.CRUDTestFunc{
    62  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    63  				return svc.Read(&ReadRequest{ID: ctx.ID, Zone: zone})
    64  			},
    65  		},
    66  		Updates: []*testutil.CRUDTestFunc{
    67  			{
    68  				Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    69  					return svc.Update(&UpdateRequest{
    70  						ID:          ctx.ID,
    71  						Name:        pointer.NewString(name + "-upd"),
    72  						Description: pointer.NewString("test-upd"),
    73  						Zone:        zone,
    74  					})
    75  				},
    76  			},
    77  		},
    78  		Delete: &testutil.CRUDTestDeleteFunc{
    79  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error {
    80  				return svc.Delete(&DeleteRequest{ID: ctx.ID, Zone: zone})
    81  			},
    82  		},
    83  		Shutdown: func(ctx *testutil.CRUDTestContext, caller sacloud.APICaller) error {
    84  			return svc.Shutdown(&ShutdownRequest{
    85  				Zone:          zone,
    86  				ID:            ctx.ID,
    87  				ForceShutdown: true,
    88  			})
    89  		},
    90  		Cleanup: nil,
    91  	})
    92  }