1
0
mirror of https://github.com/umputun/reproxy.git synced 2024-11-24 08:12:31 +02:00
reproxy/app/proxy/error_reporter_test.go
Umputun 5743109210
Nice error (#61)
* add support of html error reporting with custom templates

* typo

* formatting

* better template load error msg
2021-04-30 04:03:36 -05:00

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())
}