diff options
author | Torsten Juergeleit <torsten.juergeleit@gmail.com> | 2017-05-31 16:34:05 +0200 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-05-31 10:34:05 -0400 |
commit | fdf1164aee36d60b34ca82c07fe02b68e972f53a (patch) | |
tree | decf173e9b6fb8d8f3c10463d065ad9234fc3391 /utils/httpclient_test.go | |
parent | ddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7 (diff) | |
download | chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.gz chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.bz2 chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.zip |
PLT-5705 Created a single source of http.Client creation logic with internet proxy support, reasonable timeouts and optional insecure connections (#6503)
Diffstat (limited to 'utils/httpclient_test.go')
-rw-r--r-- | utils/httpclient_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/utils/httpclient_test.go b/utils/httpclient_test.go new file mode 100644 index 000000000..17353a4e7 --- /dev/null +++ b/utils/httpclient_test.go @@ -0,0 +1,42 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package utils + +import ( + "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "testing" +) + +func TestHttpClientWithProxy(t *testing.T) { + proxy := createProxyServer() + defer proxy.Close() + os.Setenv("HTTP_PROXY", proxy.URL) + + client := HttpClient() + resp, err := client.Get("http://acme.com") + if err != nil { + t.Fatal(err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fatal(err) + } + if string(body) != "proxy" { + t.FailNow() + } +} + +func createProxyServer() *httptest.Server { + return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + w.Header().Set("Content-Type", "text/plain; charset=us-ascii") + fmt.Fprint(w, "proxy") + })) +} |