aboutsummaryrefslogtreecommitdiffstats
path: root/modules/httplib/mock.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/httplib/mock.go')
-rw-r--r--modules/httplib/mock.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/httplib/mock.go b/modules/httplib/mock.go
new file mode 100644
index 0000000000..7d284e86fb
--- /dev/null
+++ b/modules/httplib/mock.go
@@ -0,0 +1,35 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package httplib
+
+import (
+ "bytes"
+ "net/http"
+)
+
+type MockResponseWriter struct {
+ header http.Header
+
+ StatusCode int
+ BodyBuffer bytes.Buffer
+}
+
+func (m *MockResponseWriter) Header() http.Header {
+ return m.header
+}
+
+func (m *MockResponseWriter) Write(bytes []byte) (int, error) {
+ if m.StatusCode == 0 {
+ m.StatusCode = http.StatusOK
+ }
+ return m.BodyBuffer.Write(bytes)
+}
+
+func (m *MockResponseWriter) WriteHeader(statusCode int) {
+ m.StatusCode = statusCode
+}
+
+func NewMockResponseWriter() *MockResponseWriter {
+ return &MockResponseWriter{header: http.Header{}}
+}