fix(all): introduce and use iox.CopyContext (#380)
* fix(all): introduce and use iox.CopyContext This PR is part of https://github.com/ooni/probe/issues/1417. In https://github.com/ooni/probe-cli/pull/379 we introduced a context aware wrapper for io.ReadAll (formerly ioutil.ReadAll). Here we introduce a context aware wrapper for io.Copy. * fix(humanize): more significant digits * fix: rename humanize files to follow the common pattern * fix aligment * fix test
This commit is contained in:
@@ -7,7 +7,7 @@ import "fmt"
|
||||
// specially tailored for printing download speeds.
|
||||
func SI(value float64, unit string) string {
|
||||
value, prefix := reduce(value)
|
||||
return fmt.Sprintf("%3.0f %s%s", value, prefix, unit)
|
||||
return fmt.Sprintf("%6.2f %s%s", value, prefix, unit)
|
||||
}
|
||||
|
||||
// reduce reduces value to a base value and a unit prefix. For
|
||||
@@ -0,0 +1,30 @@
|
||||
package humanize
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGood(t *testing.T) {
|
||||
if v := SI(128, "bit/s"); v != "128.00 bit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(1280, "bit/s"); v != " 1.28 kbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(12800, "bit/s"); v != " 12.80 kbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(128000, "bit/s"); v != "128.00 kbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(1280000, "bit/s"); v != " 1.28 Mbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(12800000, "bit/s"); v != " 12.80 Mbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(128000000, "bit/s"); v != "128.00 Mbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
if v := SI(1280000000, "bit/s"); v != " 1.28 Gbit/s" {
|
||||
t.Fatal("unexpected result", v)
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package humanize
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGood(t *testing.T) {
|
||||
if SI(128, "bit/s") != "128 bit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(1280, "bit/s") != " 1 kbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(12800, "bit/s") != " 13 kbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(128000, "bit/s") != "128 kbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(1280000, "bit/s") != " 1 Mbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(12800000, "bit/s") != " 13 Mbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(128000000, "bit/s") != "128 Mbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
if SI(1280000000, "bit/s") != " 1 Gbit/s" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user