github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/nfs/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 nfs 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/sacloud/libsacloud/v2/helper/wait" 22 "github.com/sacloud/libsacloud/v2/sacloud" 23 "github.com/sacloud/libsacloud/v2/sacloud/pointer" 24 "github.com/sacloud/libsacloud/v2/sacloud/testutil" 25 "github.com/sacloud/libsacloud/v2/sacloud/types" 26 "github.com/stretchr/testify/require" 27 ) 28 29 func TestNFSService_convertUpdateRequest(t *testing.T) { 30 ctx := context.Background() 31 caller := testutil.SingletonAPICaller() 32 name := testutil.ResourceName("nfs-service") 33 zone := testutil.TestZone() 34 35 // setup 36 swOp := sacloud.NewSwitchOp(caller) 37 sw, err := swOp.Create(ctx, zone, &sacloud.SwitchCreateRequest{Name: name}) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 current, err := New(caller).CreateWithContext(ctx, &CreateRequest{ 43 Zone: zone, 44 Name: name, 45 Description: "desc", 46 Tags: types.Tags{"tag1", "tag2"}, 47 SwitchID: sw.ID, 48 Plan: types.NFSPlans.SSD, 49 Size: 100, 50 IPAddresses: []string{"192.168.0.101"}, 51 NetworkMaskLen: 24, 52 DefaultRoute: "192.168.0.1", 53 }) 54 if err != nil { 55 t.Fatal(err) 56 } 57 58 defer func() { 59 nfsOp := sacloud.NewNFSOp(caller) 60 nfsOp.Shutdown(ctx, zone, current.ID, &sacloud.ShutdownOption{Force: true}) // nolint 61 wait.UntilNFSIsDown(ctx, nfsOp, zone, current.ID) // nolint 62 nfsOp.Delete(ctx, zone, current.ID) // nolint 63 swOp.Delete(ctx, zone, sw.ID) // nolint 64 }() 65 66 // test 67 cases := []struct { 68 in *UpdateRequest 69 expect *ApplyRequest 70 }{ 71 { 72 in: &UpdateRequest{ 73 Zone: zone, 74 ID: current.ID, 75 Name: pointer.NewString(current.Name + "-upd"), 76 }, 77 expect: &ApplyRequest{ 78 ID: current.ID, 79 Zone: zone, 80 Name: current.Name + "-upd", 81 Description: current.Description, 82 Tags: current.Tags, 83 IconID: current.IconID, 84 SwitchID: current.SwitchID, 85 Plan: types.NFSPlans.SSD, 86 Size: 100, 87 IPAddresses: current.IPAddresses, 88 NetworkMaskLen: current.NetworkMaskLen, 89 DefaultRoute: current.DefaultRoute, 90 }, 91 }, 92 } 93 94 for _, tc := range cases { 95 req, err := tc.in.ApplyRequest(ctx, caller) 96 require.NoError(t, err) 97 require.EqualValues(t, tc.expect, req) 98 } 99 }