Skip to content

Commit

Permalink
fix: fixed mux usage in others unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriwe committed Jun 11, 2023
1 parent a031aa3 commit 12e2db9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
12 changes: 6 additions & 6 deletions compose/circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestCircuit_setupCircuit(t *testing.T) {
t.Run("Succeed", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand All @@ -40,7 +40,7 @@ func TestCircuit_setupCircuit(t *testing.T) {
t.Run("Invalid Knot", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand All @@ -67,7 +67,7 @@ func TestCircuit_handle(t *testing.T) {
t.Run("Succeed", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestCircuit_serve(t *testing.T) {
t.Run("Succeed", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCircuit_Serve(t *testing.T) {
t.Run("Succeed", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestCircuit_Serve(t *testing.T) {
t.Run("Invalid Setup", func(tt *testing.T) {
service := network.ListenAny()
defer service.Close()
go utilshttp.NewMux(service)
utilshttp.NewMux(service)
c := Circuit{
Network: service.Addr().Network(),
Address: service.Addr().String(),
Expand Down
13 changes: 4 additions & 9 deletions proxies/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gavv/httpexpect/v2"
"github.com/shoriwe/fullproxy/v3/reverse"
httputils "github.com/shoriwe/fullproxy/v3/utils/http"
"github.com/shoriwe/fullproxy/v3/utils/network"
"github.com/stretchr/testify/assert"
)
Expand All @@ -24,14 +25,8 @@ func TestHTTP_Addr(t *testing.T) {
}

func TestHTTP_Serve(t *testing.T) {
testMessage := "TEST"
echoRoute := "/echo"
setupHTTP := func(tt *testing.T, proxy, service net.Listener) *httpexpect.Expect {
mux := http.NewServeMux()
mux.HandleFunc(echoRoute, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(testMessage))
})
go http.Serve(service, mux)
httputils.NewMux(service)
proxyUrl, _ := url.Parse("http://" + proxy.Addr().String())
return httpexpect.WithConfig(
httpexpect.Config{
Expand All @@ -57,7 +52,7 @@ func TestHTTP_Serve(t *testing.T) {
}
defer h.Close()
go h.Serve()
expect.GET(echoRoute).Expect().Status(http.StatusOK).Body().Contains(testMessage)
expect.GET(httputils.EchoRoute).Expect().Status(http.StatusOK).Body().Contains(httputils.EchoMsg)
})
t.Run("Reverse", func(tt *testing.T) {
service := network.ListenAny()
Expand Down Expand Up @@ -89,7 +84,7 @@ func TestHTTP_Serve(t *testing.T) {
}
defer h.Close()
go h.Serve()
expect.GET(echoRoute).Expect().Status(http.StatusOK).Body().Contains(testMessage)
expect.GET(httputils.EchoRoute).Expect().Status(http.StatusOK).Body().Contains(httputils.EchoMsg)
controlCh <- struct{}{}
})

Expand Down

0 comments on commit 12e2db9

Please sign in to comment.