From 68a28b3a5ddde2d6f4331ee29528e41be9491076 Mon Sep 17 00:00:00 2001 From: corebreaker Date: Tue, 18 Jul 2017 15:37:39 +0300 Subject: [PATCH 1/3] Add GetReporter method for getting the Reporter Former-commit-id: 4c3f6144c2303b2f8f740251335454a80f51d457 --- core/router/api_builder.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/router/api_builder.go b/core/router/api_builder.go index 74569644..b72b569f 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -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. // From 6b747affad1e3a8bc25713181d043baddea27dfe Mon Sep 17 00:00:00 2001 From: corebreaker Date: Tue, 18 Jul 2017 16:27:12 +0300 Subject: [PATCH 2/3] Tests failed, maybe net port problem Former-commit-id: c02333acba09575a655cde67d41e11223ec9d1c0 --- core/host/proxy_test.go | 103 +++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 43 deletions(-) diff --git a/core/host/proxy_test.go b/core/host/proxy_test.go index d5e39dce..a3dd584e 100644 --- a/core/host/proxy_test.go +++ b/core/host/proxy_test.go @@ -2,59 +2,76 @@ package host_test import ( - "net" - "net/url" - "testing" + "net" + "net/url" + "testing" + "time" - "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/core/host" - "github.com/kataras/iris/httptest" + "github.com/kataras/iris" + "github.com/kataras/iris/context" + "github.com/kataras/iris/core/host" + "github.com/kataras/iris/httptest" ) func TestProxy(t *testing.T) { - expectedIndex := "ok /" - expectedAbout := "ok /about" - unexpectedRoute := "unexpected" + expectedIndex := "ok /" + expectedAbout := "ok /about" + unexpectedRoute := "unexpected" - // proxySrv := iris.New() - u, err := url.Parse("https://localhost:4444") - if err != nil { - t.Fatalf("%v while parsing url", err) - } + // proxySrv := iris.New() + u, err := url.Parse("https://localhost:4444") + if err != nil { + t.Fatalf("%v while parsing url", err) + } - // p := host.ProxyHandler(u) - // transport := &http.Transport{ - // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - // } - // p.Transport = transport - // proxySrv.Downgrade(p.ServeHTTP) - // go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler) + // p := host.ProxyHandler(u) + // transport := &http.Transport{ + // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + // } + // p.Transport = transport + // 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) - app := iris.New() - app.Get("/", func(ctx context.Context) { - ctx.WriteString(expectedIndex) - }) + addr := &net.TCPAddr{ + IP: net.IPv4(127, 0, 0, 1), + Port: 0, + } - app.Get("/about", func(ctx context.Context) { - ctx.WriteString(expectedAbout) - }) + listener, err := net.ListenTCP("tcp", addr) + if err != nil { + t.Fatalf("%v while creating listener", err) + } - app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { - ctx.WriteString(unexpectedRoute) - }) + go proxy.Serve(listener) // should be localhost/127.0.0.1:80 but travis throws permission denied. - l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied. - if err != nil { - t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err) - } - // main server - go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner) + t.Log(listener.Addr().String()) + <-time.After(time.Second) + t.Log(listener.Addr().String()) - e := httptest.NewInsecure(t, httptest.URL("http://localhost:2017")) - 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) + app := iris.New() + app.Get("/", func(ctx context.Context) { + ctx.WriteString(expectedIndex) + }) + + app.Get("/about", func(ctx context.Context) { + ctx.WriteString(expectedAbout) + }) + + app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { + ctx.WriteString(unexpectedRoute) + }) + + l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied. + if err != nil { + t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err) + } + // main server + go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner) + + 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) } From 0e3b29c55167bb35a011c7d61b19d3ac844b3535 Mon Sep 17 00:00:00 2001 From: corebreaker Date: Tue, 18 Jul 2017 23:13:05 +0300 Subject: [PATCH 3/3] Gofmt Former-commit-id: a665e3f1253feb0d520c79ea499cba1f205c9c4f --- core/host/proxy_test.go | 112 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/core/host/proxy_test.go b/core/host/proxy_test.go index a3dd584e..8c4b4921 100644 --- a/core/host/proxy_test.go +++ b/core/host/proxy_test.go @@ -2,76 +2,76 @@ package host_test import ( - "net" - "net/url" - "testing" - "time" + "net" + "net/url" + "testing" + "time" - "github.com/kataras/iris" - "github.com/kataras/iris/context" - "github.com/kataras/iris/core/host" - "github.com/kataras/iris/httptest" + "github.com/kataras/iris" + "github.com/kataras/iris/context" + "github.com/kataras/iris/core/host" + "github.com/kataras/iris/httptest" ) func TestProxy(t *testing.T) { - expectedIndex := "ok /" - expectedAbout := "ok /about" - unexpectedRoute := "unexpected" + expectedIndex := "ok /" + expectedAbout := "ok /about" + unexpectedRoute := "unexpected" - // proxySrv := iris.New() - u, err := url.Parse("https://localhost:4444") - if err != nil { - t.Fatalf("%v while parsing url", err) - } + // proxySrv := iris.New() + u, err := url.Parse("https://localhost:4444") + if err != nil { + t.Fatalf("%v while parsing url", err) + } - // p := host.ProxyHandler(u) - // transport := &http.Transport{ - // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - // } - // p.Transport = transport - // proxySrv.Downgrade(p.ServeHTTP) - // go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler) + // p := host.ProxyHandler(u) + // transport := &http.Transport{ + // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + // } + // p.Transport = transport + // proxySrv.Downgrade(p.ServeHTTP) + // go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler) - proxy := host.NewProxy("", u) + proxy := host.NewProxy("", u) - addr := &net.TCPAddr{ - IP: net.IPv4(127, 0, 0, 1), - Port: 0, - } + 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) - } + 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. + 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()) + t.Log(listener.Addr().String()) + <-time.After(time.Second) + t.Log(listener.Addr().String()) - app := iris.New() - app.Get("/", func(ctx context.Context) { - ctx.WriteString(expectedIndex) - }) + app := iris.New() + app.Get("/", func(ctx context.Context) { + ctx.WriteString(expectedIndex) + }) - app.Get("/about", func(ctx context.Context) { - ctx.WriteString(expectedAbout) - }) + app.Get("/about", func(ctx context.Context) { + ctx.WriteString(expectedAbout) + }) - app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { - ctx.WriteString(unexpectedRoute) - }) + app.OnErrorCode(iris.StatusNotFound, func(ctx context.Context) { + ctx.WriteString(unexpectedRoute) + }) - l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied. - if err != nil { - t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err) - } - // main server - go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner) + l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied. + if err != nil { + t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err) + } + // main server + go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner) - 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) + 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) }