Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:50:02 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:50:02 +0300
commitab00ebdb114513eb3c77b6b45c5adf7848b1fc87 (patch)
tree4e974c6b3678f23b25de9093f2f8f0aa3e57e827 /logging_test.go
parent8b6077ea12539ec80d531c8f2a1a8b0188766d2e (diff)
Test logging
Diffstat (limited to 'logging_test.go')
-rw-r--r--logging_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/logging_test.go b/logging_test.go
new file mode 100644
index 00000000..e6551047
--- /dev/null
+++ b/logging_test.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "fmt"
+ "github.com/stretchr/testify/assert"
+ "net/http"
+ "testing"
+)
+
+func testLogWithStatus(ww http.ResponseWriter, r *http.Request) {
+ w := newLoggingResponseWriter(ww)
+ defer w.Log(r)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprint(&w, "with-status")
+}
+
+func testLogWithoutStatus(ww http.ResponseWriter, r *http.Request) {
+ w := newLoggingResponseWriter(ww)
+ defer w.Log(r)
+ fmt.Fprint(&w, "no-status")
+}
+
+func testLogWithDoubleStatus(ww http.ResponseWriter, r *http.Request) {
+ w := newLoggingResponseWriter(ww)
+ defer w.Log(r)
+ w.WriteHeader(http.StatusOK)
+ http.Redirect(&w, r, "/test", 301)
+}
+
+func TestLoggingWriter(t *testing.T) {
+ assert.HTTPBodyContains(t, testLogWithStatus, "GET", "/test", nil, "with-status")
+ assert.HTTPBodyContains(t, testLogWithoutStatus, "GET", "/test", nil, "no-status")
+ assert.HTTPSuccess(t, testLogWithDoubleStatus, "GET", "/test", nil)
+}