2021-02-02 12:05:47 +01:00
|
|
|
package netxlogger
|
|
|
|
|
|
|
|
import (
|
2021-06-15 11:57:40 +02:00
|
|
|
"context"
|
2021-02-02 12:05:47 +01:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/apex/log/handlers/discard"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
|
2021-09-28 12:42:01 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGood(t *testing.T) {
|
|
|
|
log.SetHandler(discard.Default)
|
|
|
|
client := netx.NewHTTPClient()
|
|
|
|
client.ConfigureDNS("udp", "dns.google.com:53")
|
|
|
|
req, err := http.NewRequest("GET", "http://www.facebook.com", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
req = req.WithContext(modelx.WithMeasurementRoot(req.Context(), &modelx.MeasurementRoot{
|
|
|
|
Beginning: time.Now(),
|
|
|
|
Handler: NewHandler(log.Log),
|
|
|
|
}))
|
|
|
|
resp, err := client.HTTPClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("expected non-nil resp here")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2021-09-28 12:42:01 +02:00
|
|
|
_, err = netxlite.ReadAllContext(context.Background(), resp.Body)
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
client.HTTPClient.CloseIdleConnections()
|
|
|
|
}
|