Skip to content

Commit

Permalink
test: Handle kB units in size_test.go (#5900)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored Jul 23, 2020
1 parent b89e355 commit 80e6c19
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion posting/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func Test21MillionDataSetSize(t *testing.T) {
func filterUnit(line string) (string, error) {
words := strings.Split(line, " ")
for _, word := range words {
if strings.Contains(word, "MB") || strings.Contains(word, "GB") {
if strings.Contains(word, "MB") || strings.Contains(word, "GB") ||
strings.Contains(word, "kB") {
return strings.TrimSpace(word), nil
}
}
Expand All @@ -227,6 +228,13 @@ func filterUnit(line string) (string, error) {

// convertToBytes converts the unit into bytes.
func convertToBytes(unit string) (uint32, error) {
if strings.Contains(unit, "kB") {
kb, err := strconv.ParseFloat(unit[0:len(unit)-2], 64)
if err != nil {
return 0, err
}
return uint32(kb * 1024.0), nil
}
if strings.Contains(unit, "MB") {
mb, err := strconv.ParseFloat(unit[0:len(unit)-2], 64)
if err != nil {
Expand Down

0 comments on commit 80e6c19

Please sign in to comment.