mirror of
https://github.com/umputun/reproxy.git
synced 2024-11-25 23:52:43 +03:00
5743109210
* add support of html error reporting with custom templates * typo * formatting * better template load error msg
34 lines
857 B
Go
34 lines
857 B
Go
package proxy
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestErrorReporter_ReportShort(t *testing.T) {
|
|
er := ErrorReporter{}
|
|
wr := httptest.NewRecorder()
|
|
er.Report(wr, 502)
|
|
assert.Equal(t, 502, wr.Code)
|
|
assert.Equal(t, "Server error\n", wr.Body.String())
|
|
}
|
|
|
|
func TestErrorReporter_ReportNice(t *testing.T) {
|
|
er := ErrorReporter{Nice: true}
|
|
wr := httptest.NewRecorder()
|
|
er.Report(wr, 502)
|
|
assert.Equal(t, 502, wr.Code)
|
|
assert.Contains(t, wr.Body.String(), "<title>Bad Gateway</title>")
|
|
assert.Contains(t, wr.Body.String(), "<p>Sorry for the inconvenience")
|
|
}
|
|
|
|
func TestErrorReporter_BadTemplate(t *testing.T) {
|
|
er := ErrorReporter{Nice: true, Template: "xxx {{."}
|
|
wr := httptest.NewRecorder()
|
|
er.Report(wr, 502)
|
|
assert.Equal(t, 502, wr.Code)
|
|
assert.Equal(t, "Server error\n", wr.Body.String())
|
|
}
|