summaryrefslogtreecommitdiffstats
path: root/integrations/integration_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-02-12 15:09:43 +0000
committerGitHub <noreply@github.com>2019-02-12 15:09:43 +0000
commit2a03e96bceadfcc5e18bd61e755980ee72dcdb15 (patch)
tree2ecc1848c76fe458f10dffe568a8bb0cdc0f32ee /integrations/integration_test.go
parent296814e887f9bcf0b1d44552deaf40e89e08ab50 (diff)
downloadgitea-2a03e96bceadfcc5e18bd61e755980ee72dcdb15.tar.gz
gitea-2a03e96bceadfcc5e18bd61e755980ee72dcdb15.zip
Allow markdown files to read from the LFS (#5787)
This PR makes it possible for the markdown renderer to render images and media straight from the LFS. Fix #5746 Signed-off-by: Andrew Thornton [art27@cantab.net](mailto:art27@cantab.net)
Diffstat (limited to 'integrations/integration_test.go')
-rw-r--r--integrations/integration_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index ba3c7e3071..d300e4a38a 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -35,6 +35,23 @@ import (
var mac *macaron.Macaron
+type NilResponseRecorder struct {
+ httptest.ResponseRecorder
+ Length int
+}
+
+func (n *NilResponseRecorder) Write(b []byte) (int, error) {
+ n.Length = n.Length + len(b)
+ return len(b), nil
+}
+
+// NewRecorder returns an initialized ResponseRecorder.
+func NewNilResponseRecorder() *NilResponseRecorder {
+ return &NilResponseRecorder{
+ ResponseRecorder: *httptest.NewRecorder(),
+ }
+}
+
func TestMain(m *testing.M) {
initIntegrationTest()
mac = routes.NewMacaron()
@@ -192,6 +209,22 @@ func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatu
return resp
}
+func (s *TestSession) MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
+ baseURL, err := url.Parse(setting.AppURL)
+ assert.NoError(t, err)
+ for _, c := range s.jar.Cookies(baseURL) {
+ req.AddCookie(c)
+ }
+ resp := MakeRequestNilResponseRecorder(t, req, expectedStatus)
+
+ ch := http.Header{}
+ ch.Add("Cookie", strings.Join(resp.HeaderMap["Set-Cookie"], ";"))
+ cr := http.Request{Header: ch}
+ s.jar.SetCookies(baseURL, cr.Cookies())
+
+ return resp
+}
+
const userPassword = "password"
var loginSessionCache = make(map[string]*TestSession, 10)
@@ -305,6 +338,18 @@ func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.
return recorder
}
+func MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
+ recorder := NewNilResponseRecorder()
+ mac.ServeHTTP(recorder, req)
+ if expectedStatus != NoExpectedStatus {
+ if !assert.EqualValues(t, expectedStatus, recorder.Code,
+ "Request: %s %s", req.Method, req.URL.String()) {
+ logUnexpectedResponse(t, &recorder.ResponseRecorder)
+ }
+ }
+ return recorder
+}
+
// logUnexpectedResponse logs the contents of an unexpected response.
func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
respBytes := recorder.Body.Bytes()