github.com/fraugster/parquet-go@v0.12.0/cmd/parquet-tool/cmds/helpers_test.go (about) 1 package cmds 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestHumanToByte(t *testing.T) { 10 data := []struct { 11 In string 12 Out int64 13 Err bool 14 }{ 15 { 16 In: "1000", 17 Out: 1000, 18 }, 19 { 20 In: "100KB", 21 Out: 100 * 1024, 22 }, 23 { 24 In: "100MB", 25 Out: 100 * 1024 * 1024, 26 }, 27 { 28 In: "100GB", 29 Out: 100 * 1024 * 1024 * 1024, 30 }, 31 { 32 In: "100TB", 33 Out: 100 * 1024 * 1024 * 1024 * 1024, 34 }, 35 { 36 In: "100PB", 37 Out: 100 * 1024 * 1024 * 1024 * 1024 * 1024, 38 }, 39 { 40 In: "100KiB", 41 Out: 100 * 1000, 42 }, 43 { 44 In: "100MiB", 45 Out: 100 * 1000 * 1000, 46 }, 47 { 48 In: "100GiB", 49 Out: 100 * 1000 * 1000 * 1000, 50 }, 51 { 52 In: "100TiB", 53 Out: 100 * 1000 * 1000 * 1000 * 1000, 54 }, 55 { 56 In: "100PiB", 57 Out: 100 * 1000 * 1000 * 1000 * 1000 * 1000, 58 }, 59 { 60 In: "ABCD", 61 Err: true, 62 }, 63 { 64 In: "ABCDPiB", 65 Err: true, 66 }, 67 } 68 69 for _, fix := range data { 70 v, err := humanToByte(fix.In) 71 if fix.Err { 72 require.Error(t, err) 73 continue 74 } 75 76 require.Equal(t, fix.Out, v, fix.In) 77 } 78 }