refactor(netxlite): expose useful HTTPTransport/DNSTransport factories (#813)

These factories will soon be useful to finish with
https://github.com/ooni/probe/issues/2135.
This commit is contained in:
Simone Basso 2022-06-09 00:30:18 +02:00 committed by GitHub
commit 1685ef75b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 224 additions and 30 deletions

View file

@ -13,6 +13,36 @@ import (
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestNewDNSOverHTTPSTransport(t *testing.T) {
const URL = "https://1.1.1.1/dns-query"
clnt := NewHTTPClientStdlib(model.DiscardLogger)
txp := NewDNSOverHTTPSTransport(clnt, URL)
ew := txp.(*dnsTransportErrWrapper)
https := ew.DNSTransport.(*DNSOverHTTPSTransport)
if https.Client != clnt {
t.Fatal("invalid client")
}
if https.URL != URL {
t.Fatal("invalid URL")
}
}
func TestNewDNSOverHTTPSTransportWithHTTPTransport(t *testing.T) {
const URL = "https://1.1.1.1/dns-query"
httpTxp := NewHTTPTransportStdlib(model.DiscardLogger)
txp := NewDNSOverHTTPSTransportWithHTTPTransport(httpTxp, URL)
ew := txp.(*dnsTransportErrWrapper)
https := ew.DNSTransport.(*DNSOverHTTPSTransport)
ewClient := https.Client.(*httpClientErrWrapper)
clnt := ewClient.HTTPClient.(*http.Client)
if clnt.Transport != httpTxp {
t.Fatal("invalid transport")
}
if https.URL != URL {
t.Fatal("invalid URL")
}
}
func TestDNSOverHTTPSTransport(t *testing.T) {
t.Run("RoundTrip", func(t *testing.T) {
t.Run("query serialization failure", func(t *testing.T) {