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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2910007033
Коммит
0027d99855
@@ -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()
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user