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

  1. package client
  2. import (
  3. "io/ioutil"
  4. "log"
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestHTTPClientMakeHTTPDialer(t *testing.T) {
  11. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  12. _, _ = w.Write([]byte("Hi!\n"))
  13. })
  14. ts := httptest.NewServer(handler)
  15. defer ts.Close()
  16. tsTLS := httptest.NewTLSServer(handler)
  17. defer tsTLS.Close()
  18. // This silences a TLS handshake error, caused by the dialer just immediately
  19. // disconnecting, which we can just ignore.
  20. tsTLS.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
  21. for _, testURL := range []string{ts.URL, tsTLS.URL} {
  22. u, err := newParsedURL(testURL)
  23. require.NoError(t, err)
  24. dialFn, err := makeHTTPDialer(testURL)
  25. require.Nil(t, err)
  26. addr, err := dialFn(u.Scheme, u.GetHostWithPath())
  27. require.NoError(t, err)
  28. require.NotNil(t, addr)
  29. }
  30. }