Browse Source

test: don't use foo-bar.net in TestHTTPClientMakeHTTPDialer (#5997)

This test relied on connecting to the external site `foo-bar.net`, and (predictably) the site went down and broke all of our CI runs. This changes it to use local HTTP servers instead.
pull/6000/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
f54f80bf0d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 5 deletions
  1. +18
    -5
      rpc/jsonrpc/client/http_json_client_test.go

+ 18
- 5
rpc/jsonrpc/client/http_json_client_test.go View File

@ -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:pass@foo-bar.net: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)
}
}

Loading…
Cancel
Save