summaryrefslogtreecommitdiffstats
path: root/app/apptestlib.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/apptestlib.go')
-rw-r--r--app/apptestlib.go30
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()
+}