58adb68b2c
* refactor: move tracex outside of engine/netx Consistently with https://github.com/ooni/probe/issues/2121 and https://github.com/ooni/probe/issues/2115, we can now move tracex outside of engine/netx. The main reason why this makes sense now is that the package is now changed significantly from the one that we imported from ooni/probe-engine. We have improved its implementation, which had not been touched significantly for quite some time, and converted it to unit testing. I will document tomorrow some extra work I'd like to do with this package but likely could not do $soon. * go fmt * regen tutorials
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package dialer
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/apex/log"
|
|
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
"github.com/ooni/probe-cli/v3/internal/tracex"
|
|
)
|
|
|
|
func TestNewCreatesTheExpectedChain(t *testing.T) {
|
|
saver := &tracex.Saver{}
|
|
dlr := New(&Config{
|
|
ContextByteCounting: true,
|
|
DialSaver: saver,
|
|
Logger: log.Log,
|
|
ProxyURL: &url.URL{},
|
|
ReadWriteSaver: saver,
|
|
}, netxlite.DefaultResolver)
|
|
bcd, ok := dlr.(*bytecounter.ContextAwareDialer)
|
|
if !ok {
|
|
t.Fatal("not a byteCounterDialer")
|
|
}
|
|
_, ok = bcd.Dialer.(*netxlite.MaybeProxyDialer)
|
|
if !ok {
|
|
t.Fatal("not a proxyDialer")
|
|
}
|
|
// We can safely stop here: the rest is tested by
|
|
// the internal/netxlite package
|
|
}
|
|
|
|
func TestDialerNewSuccess(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skip test in short mode")
|
|
}
|
|
log.SetLevel(log.DebugLevel)
|
|
d := New(&Config{Logger: log.Log}, netxlite.DefaultResolver)
|
|
txp := &http.Transport{DialContext: d.DialContext}
|
|
client := &http.Client{Transport: txp}
|
|
resp, err := client.Get("http://www.google.com")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
resp.Body.Close()
|
|
}
|