mirror of
https://github.com/umputun/reproxy.git
synced 2024-11-24 08:12:31 +02: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())
|
|
}
|