You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
882 B

package client
import (
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestHTTPClientMakeHTTPDialer(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hi!\n"))
})
ts := httptest.NewServer(handler)
defer ts.Close()
tsTLS := httptest.NewTLSServer(handler)
defer tsTLS.Close()
// This silences a TLS handshake error, caused by the dialer just immediately
// disconnecting, which we can just ignore.
tsTLS.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
for _, testURL := range []string{ts.URL, tsTLS.URL} {
u, err := newParsedURL(testURL)
require.NoError(t, err)
dialFn, err := makeHTTPDialer(testURL)
require.Nil(t, err)
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
require.NoError(t, err)
require.NotNil(t, addr)
}
}