mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Tests failed, maybe net port problem
Former-commit-id: c02333acba09575a655cde67d41e11223ec9d1c0
This commit is contained in:
parent
68a28b3a5d
commit
6b747affad
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user