refactor(oohelperd): better distinguish different helpers (#434)

Part of https://github.com/ooni/probe/issues/1733
This commit is contained in:
Simone Basso 2021-08-17 11:23:53 +02:00 committed by GitHub
commit ce854e8ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 48 additions and 45 deletions

View file

@ -1,59 +0,0 @@
package internal_test
import (
"context"
"errors"
"net/http"
"strings"
"sync"
"testing"
"github.com/ooni/probe-cli/v3/internal/cmd/oohelperd/internal"
)
func TestHTTPDoWithInvalidURL(t *testing.T) {
ctx := context.Background()
wg := new(sync.WaitGroup)
httpch := make(chan internal.CtrlHTTPResponse, 1)
wg.Add(1)
go internal.HTTPDo(ctx, &internal.HTTPConfig{
Client: http.DefaultClient,
Headers: nil,
MaxAcceptableBody: 1 << 24,
Out: httpch,
URL: "http://[::1]aaaa",
Wg: wg,
})
// wait for measurement steps to complete
wg.Wait()
resp := <-httpch
if resp.Failure == nil || !strings.HasSuffix(*resp.Failure, `invalid port "aaaa" after host`) {
t.Fatal("not the failure we expected")
}
}
func TestHTTPDoWithHTTPTransportFailure(t *testing.T) {
expected := errors.New("mocked error")
ctx := context.Background()
wg := new(sync.WaitGroup)
httpch := make(chan internal.CtrlHTTPResponse, 1)
wg.Add(1)
go internal.HTTPDo(ctx, &internal.HTTPConfig{
Client: &http.Client{
Transport: internal.FakeTransport{
Err: expected,
},
},
Headers: nil,
MaxAcceptableBody: 1 << 24,
Out: httpch,
URL: "http://www.x.org",
Wg: wg,
})
// wait for measurement steps to complete
wg.Wait()
resp := <-httpch
if resp.Failure == nil || !strings.HasSuffix(*resp.Failure, "mocked error") {
t.Fatal("not the error we expected")
}
}