Merge pull request #679 from corebreaker/get-reporter

Add GetReporter method for getting the Reporter. Fixes #678

Former-commit-id: c4aea6edbd657dec9c76e01b91fe1570f2b198f8
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-07-18 23:22:14 +03:00 committed by GitHub
commit a2af84336f
2 changed files with 24 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"net"
"net/url"
"testing"
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
@ -31,7 +32,23 @@ func TestProxy(t *testing.T) {
// proxySrv.Downgrade(p.ServeHTTP)
// go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler)
go host.NewProxy("localhost:2017", u).ListenAndServe() // should be localhost/127.0.0.1:80 but travis throws permission denied.
proxy := host.NewProxy("", u)
addr := &net.TCPAddr{
IP: net.IPv4(127, 0, 0, 1),
Port: 0,
}
listener, err := net.ListenTCP("tcp", addr)
if err != nil {
t.Fatalf("%v while creating listener", err)
}
go proxy.Serve(listener) // should be localhost/127.0.0.1:80 but travis throws permission denied.
t.Log(listener.Addr().String())
<-time.After(time.Second)
t.Log(listener.Addr().String())
app := iris.New()
app.Get("/", func(ctx context.Context) {
@ -53,7 +70,7 @@ func TestProxy(t *testing.T) {
// main server
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner)
e := httptest.NewInsecure(t, httptest.URL("http://localhost:2017"))
e := httptest.NewInsecure(t, httptest.URL("http://"+listener.Addr().String()))
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
e.GET("/about").Expect().Status(iris.StatusOK).Body().Equal(expectedAbout)
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(unexpectedRoute)

View File

@ -108,6 +108,11 @@ func (rb *APIBuilder) GetReport() error {
return rb.reporter.Return()
}
// GetReporter returns the reporter for adding errors
func (rb *APIBuilder) GetReporter() *errors.Reporter {
return rb.reporter
}
// Handle registers a route to the server's rb.
// if empty method is passed then handler(s) are being registered to all methods, same as .Any.
//