diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-09-07 09:24:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-07 09:24:18 -0400 |
commit | 0027d998555d47f9a75a896d8c6c85a8b4645ad0 (patch) | |
tree | 4a15d63c143e9891921d75f102dd008852c9abb2 /app/apptestlib.go | |
parent | 291000703320cc53c3bdecd2553fa4a3021d7234 (diff) | |
download | chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.tar.gz chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.tar.bz2 chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.zip |
MM-11855 Add App.HTTPService to allow mocking of HTTP client (#9359)
* MM-11855 Add App.HTTPService to allow mocking of HTTP client
* Initialize HTTPService earlier
Diffstat (limited to 'app/apptestlib.go')
-rw-r--r-- | app/apptestlib.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/apptestlib.go b/app/apptestlib.go index 48783f49c..c0d2cfaa2 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -6,6 +6,8 @@ package app import ( "io" "io/ioutil" + "net/http" + "net/http/httptest" "os" "path/filepath" "time" @@ -33,6 +35,8 @@ type TestHelper struct { tempConfigPath string tempWorkspace string + + MockedHTTPService *MockedHTTPService } type persistentTestStore struct { @@ -163,6 +167,13 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { return me } +func (me *TestHelper) MockHTTPService(handler http.Handler) *TestHelper { + me.MockedHTTPService = MakeMockedHTTPService(handler) + me.App.HTTPService = me.MockedHTTPService + + return me +} + func (me *TestHelper) MakeEmail() string { return "success_" + model.NewId() + "@simulator.amazonses.com" } @@ -503,3 +514,22 @@ func (me *FakeClusterInterface) sendClearRoleCacheMessage() { Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES, }) } + +type MockedHTTPService struct { + Server *httptest.Server +} + +func MakeMockedHTTPService(handler http.Handler) *MockedHTTPService { + return &MockedHTTPService{ + Server: httptest.NewServer(handler), + } +} + +func (h *MockedHTTPService) MakeClient(trustURLs bool) *http.Client { + return h.Server.Client() +} + +func (h *MockedHTTPService) Close() { + h.Server.CloseClientConnections() + h.Server.Close() +} |