github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/sim/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 sim 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/sacloud/libsacloud/v2/helper/cleanup" 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 TestSIMService_convertUpdateRequest(t *testing.T) { 30 ctx := context.Background() 31 caller := testutil.SingletonAPICaller() 32 name := testutil.ResourceName("sim-service") 33 34 // setup 35 simOp := sacloud.NewSIMOp(caller) 36 sim, err := New(caller).CreateWithContext(ctx, &CreateRequest{ 37 Name: name, 38 Description: "desc", 39 Tags: types.Tags{"tag1", "tag2"}, 40 ICCID: "aaaaaaaa", 41 PassCode: "bbbbbbbb", 42 Activate: true, 43 IMEI: "cccccccc", 44 Carriers: []*sacloud.SIMNetworkOperatorConfig{ 45 { 46 Allow: true, 47 Name: types.SIMOperators.Docomo.String(), 48 }, 49 }, 50 }) 51 if err != nil { 52 t.Fatal(err) 53 } 54 55 defer func() { 56 cleanup.DeleteSIM(ctx, simOp, sim.ID) // nolint 57 }() 58 59 // test 60 cases := []struct { 61 in *UpdateRequest 62 expect *ApplyRequest 63 }{ 64 { 65 in: &UpdateRequest{ 66 ID: sim.ID, 67 Name: pointer.NewString(name + "-upd"), 68 Activate: pointer.NewBool(false), 69 IMEI: pointer.NewString(""), 70 Carriers: &[]*sacloud.SIMNetworkOperatorConfig{ 71 {Allow: true, Name: types.SIMOperators.SoftBank.String()}, 72 }, 73 }, 74 expect: &ApplyRequest{ 75 ID: sim.ID, 76 Name: name + "-upd", 77 Description: sim.Description, 78 Tags: sim.Tags, 79 IconID: sim.IconID, 80 ICCID: sim.ICCID, 81 PassCode: "", 82 Activate: false, 83 IMEI: "", 84 Carriers: []*sacloud.SIMNetworkOperatorConfig{ 85 { 86 Allow: true, 87 Name: types.SIMOperators.SoftBank.String(), 88 }, 89 }, 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 }