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

logging_test.go - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e6551047c636256613e06c1e0c8f999cda489d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}