bbcd2e2280
This diff creates a new package under netx called tracex that contains everything we need to perform measurements using events tracing and postprocessing (which is the technique with which we implement most network experiments). The general idea here is to (1) create a unique package out of all of these packages; (2) clean up the code a bit (improve tests, docs, apply more recent code patterns); (3) move the resulting code as a toplevel package inside of internal. Once this is done, netx can be further refactored to avoid subpackages and we can search for more code to salvage/refactor. See https://github.com/ooni/probe/issues/2121
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/engine/netx/tracex"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
)
|
|
|
|
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()
|
|
}
|