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:
Simone Basso 2021-06-15 13:44:28 +02:00 committed by GitHub
commit 721ce95315
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 143 additions and 51 deletions

View file

@ -3,7 +3,6 @@ package engine
import (
"context"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
@ -17,6 +16,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices"
"github.com/ooni/probe-cli/v3/internal/iox"
"github.com/ooni/probe-cli/v3/internal/version"
)
@ -31,7 +31,8 @@ func TestSessionByteCounter(t *testing.T) {
t.Fatal(err)
}
defer resp.Body.Close()
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
ctx := context.Background()
if _, err := iox.CopyContext(ctx, ioutil.Discard, resp.Body); err != nil {
t.Fatal(err)
}
if s.KibiBytesSent() <= 0 || s.KibiBytesReceived() <= 0 {