64bffbd941
Before finishing the ongoing refactoring and leaving whatever is left of netx in tree, I would like to restructure it so that we'll have an easy time next time we need to modify it. Currently, every functionality lives into the `netx.go` file and we have a support file called `httptransport.go`. I would like to reorganize by topic, instead. This would allow future me to more easily perform topic-specific changes. While there, improve `netx`'s documentation and duplicate some of this documentation inside `internal/README.md` to provide pointers to previous documentation, historical context, and some help to understand the logic architecture of network extensions (aka `netx`). Part of https://github.com/ooni/probe-cli/pull/396
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package netx
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"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 TestHTTPTransportWorkingAsIntended(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skip test in short mode")
|
|
}
|
|
log.SetLevel(log.DebugLevel)
|
|
counter := bytecounter.New()
|
|
config := Config{
|
|
BogonIsError: true,
|
|
ByteCounter: counter,
|
|
CacheResolutions: true,
|
|
ContextByteCounting: true,
|
|
Logger: log.Log,
|
|
ReadWriteSaver: &tracex.Saver{},
|
|
Saver: &tracex.Saver{},
|
|
}
|
|
txp := NewHTTPTransport(config)
|
|
client := &http.Client{Transport: txp}
|
|
resp, err := client.Get("https://www.google.com")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = netxlite.ReadAllContext(context.Background(), resp.Body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = resp.Body.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if counter.Sent.Load() <= 0 {
|
|
t.Fatal("no bytes sent?!")
|
|
}
|
|
if counter.Received.Load() <= 0 {
|
|
t.Fatal("no bytes received?!")
|
|
}
|
|
if ev := config.ReadWriteSaver.Read(); len(ev) <= 0 {
|
|
t.Fatal("no R/W events?!")
|
|
}
|
|
if ev := config.Saver.Read(); len(ev) <= 0 {
|
|
t.Fatal("no non-I/O events?!")
|
|
}
|
|
}
|