refactor: move more commands to internal/cmd (#207)
* refactor: move more commands to internal/cmd Part of https://github.com/ooni/probe/issues/1335. We would like all commands to be at the same level of engine rather than inside engine (now that we can do it). * fix: update .gitignore * refactor: also move jafar outside engine * We should be good now?
This commit is contained in:
parent
6351d898d6
commit
4eeadd06a5
85 changed files with 72 additions and 65 deletions
59
internal/cmd/oohelperd/internal/http_test.go
Normal file
59
internal/cmd/oohelperd/internal/http_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue