github.com/blend/go-sdk@v1.20220411.3/fileutil/parse_file_size_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package fileutil 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func Test_FileParseSize(t *testing.T) { 17 assert := assert.New(t) 18 19 parsed, err := ParseFileSize("2gb") 20 assert.Nil(err) 21 assert.Equal(2*Gigabyte, parsed) 22 23 parsed, err = ParseFileSize("3mb") 24 assert.Nil(err) 25 assert.Equal(3*Megabyte, parsed) 26 27 parsed, err = ParseFileSize("123kb") 28 assert.Nil(err) 29 assert.Equal(123*Kilobyte, parsed) 30 31 parsed, err = ParseFileSize("12345") 32 assert.Nil(err) 33 assert.Equal(12345, parsed) 34 35 parsed, err = ParseFileSize("") 36 assert.Nil(err) 37 assert.Equal(0, parsed) 38 39 parsed, err = ParseFileSize("bogus") 40 assert.NotNil(err) 41 assert.Equal(0, parsed) 42 }