-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from wetcod/http-test1
test: don't use foo-bar.net in TestHTTPClientMakeHTTPDialer
- Loading branch information
Showing
1 changed file
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,36 @@ | ||
package client | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHTTPClientMakeHTTPDialer(t *testing.T) { | ||
remote := []string{"https://foo-bar.com:80", "http://foo-bar.net:80", "https://user:[email protected]:80"} | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
_, _ = w.Write([]byte("Hi!\n")) | ||
}) | ||
ts := httptest.NewServer(handler) | ||
defer ts.Close() | ||
|
||
for _, f := range remote { | ||
u, err := newParsedURL(f) | ||
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(f) | ||
dialFn, err := makeHTTPDialer(testURL) | ||
require.Nil(t, err) | ||
|
||
addr, err := dialFn(u.Scheme, u.GetHostWithPath()) | ||
require.NoError(t, err) | ||
require.NotNil(t, addr) | ||
} | ||
|
||
} |