2021-02-02 12:05:47 +01:00
|
|
|
package httptransport_test
|
|
|
|
|
|
|
|
import (
|
2022-05-06 12:24:03 +02:00
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
2021-02-02 12:05:47 +01:00
|
|
|
"testing"
|
|
|
|
|
2022-05-06 12:24:03 +02:00
|
|
|
"github.com/lucas-clemente/quic-go"
|
2021-02-02 12:05:47 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport"
|
2022-05-06 12:24:03 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
2021-06-30 15:19:10 +02:00
|
|
|
func TestNewHTTP3Transport(t *testing.T) {
|
2022-05-06 12:24:03 +02:00
|
|
|
// make sure we can create a working transport using this factory.
|
|
|
|
expected := errors.New("mocked error")
|
|
|
|
txp := httptransport.NewHTTP3Transport(httptransport.Config{
|
|
|
|
QUICDialer: &mocks.QUICDialer{
|
|
|
|
MockDialContext: func(ctx context.Context, network, address string,
|
|
|
|
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
|
|
|
|
return nil, expected
|
|
|
|
},
|
|
|
|
MockCloseIdleConnections: func() {
|
|
|
|
// nothing
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
req, err := http.NewRequest("GET", "https://google.com", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
resp, err := txp.RoundTrip(req)
|
|
|
|
if !errors.Is(err, expected) {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatal("expected nil resp")
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|