github.com/sacloud/iaas-api-go@v1.12.0/accessor/size_mb_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/packages-go/size" 21 "github.com/stretchr/testify/require" 22 ) 23 24 type dummySizeMBAccessor struct { 25 size int 26 } 27 28 func (d *dummySizeMBAccessor) GetSizeMB() int { 29 return d.size 30 } 31 32 func (d *dummySizeMBAccessor) SetSizeMB(size int) { 33 d.size = size 34 } 35 36 func TestSizeMBAccessor(t *testing.T) { 37 expects := []struct { 38 input int 39 expect int 40 }{ 41 { 42 input: 0, 43 expect: 0, 44 }, 45 { 46 input: 1, 47 expect: 1 * size.GiB, 48 }, 49 { 50 input: 2, 51 expect: 2 * size.GiB, 52 }, 53 } 54 55 for _, tc := range expects { 56 var target SizeMB = &dummySizeMBAccessor{} 57 58 SetSizeGB(target, tc.input) 59 require.Equal(t, tc.input, GetSizeGB(target)) 60 require.Equal(t, tc.expect, target.GetSizeMB()) 61 } 62 }