github.com/sacloud/iaas-api-go@v1.12.0/accessor/id_test.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go 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 accessor 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/iaas-api-go/types" 21 "github.com/stretchr/testify/require" 22 ) 23 24 type dummyIDAccessor struct { 25 id types.ID 26 } 27 28 func (d *dummyIDAccessor) GetID() types.ID { 29 return d.id 30 } 31 32 func (d *dummyIDAccessor) SetID(id types.ID) { 33 d.id = id 34 } 35 36 func TestIDAccessor(t *testing.T) { 37 expects := []struct { 38 input interface{} 39 expect types.ID 40 }{ 41 { 42 input: "0", 43 expect: types.Int64ID(0), 44 }, 45 { 46 input: "1", 47 expect: types.Int64ID(1), 48 }, 49 { 50 input: "2", 51 expect: types.Int64ID(2), 52 }, 53 } 54 55 for _, tc := range expects { 56 var target ID = &dummyIDAccessor{} 57 58 if _, ok := tc.input.(string); ok { 59 SetStringID(target, tc.input.(string)) 60 } else { 61 SetInt64ID(target, tc.input.(int64)) 62 } 63 64 require.Equal(t, tc.expect, target.GetID()) 65 } 66 }