package main import ( "testing" "github.com/stretchr/testify/assert" ) func TestParseFromString(t *testing.T) { tests := map[string]struct { input1 string input2 int64 }{ "KB": {input1: "5.5KB", input2: 5632}, "MB": {input1: "6.7MB", input2: 7025459}, "GB": {input1: "7.5GB", input2: 8053063680}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { by := ByteSize{} err := by.ParseFromString(tc.input1) assert.Equal(t, err, nil) assert.EqualValues(t, by.NumberRep, tc.input2) }) } } func TestParseFromNumber(t *testing.T) { tests := map[string]struct { input1 int64 input2 string }{ "KB": {input1: 528870, input2: "516.5KB"}, "MB": {input1: 7025459, input2: "6.7MB"}, "GB": {input1: 8053063680, input2: "7.5GB"}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { by := ByteSize{} by.ParseFromNumber(tc.input1) assert.EqualValues(t, by.HumanRep, tc.input2) }) } }