mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 17:19:06 +01:00
test(middleware): update bypass and rule tests
This commit is contained in:
@@ -2,8 +2,11 @@ package middleware_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -135,17 +138,31 @@ func TestReverseProxyBypass(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEntrypointBypassRoute(t *testing.T) {
|
||||
go http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("test"))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
url, err := url.Parse(srv.URL)
|
||||
expect.NoError(t, err)
|
||||
|
||||
host, port, err := net.SplitHostPort(url.Host)
|
||||
expect.NoError(t, err)
|
||||
|
||||
portInt, err := strconv.Atoi(port)
|
||||
expect.NoError(t, err)
|
||||
|
||||
expect.NoError(t, err)
|
||||
entry := entrypoint.NewEntrypoint()
|
||||
r := &route.Route{
|
||||
Alias: "test-route",
|
||||
Host: host,
|
||||
Port: routeTypes.Port{
|
||||
Proxy: 8080,
|
||||
Proxy: portInt,
|
||||
},
|
||||
}
|
||||
err := entry.SetMiddlewares([]map[string]any{
|
||||
|
||||
err = entry.SetMiddlewares([]map[string]any{
|
||||
{
|
||||
"use": "redirectHTTP",
|
||||
"bypass": []string{"route test-route"},
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestParseCommands(t *testing.T) {
|
||||
// serve tests
|
||||
{
|
||||
name: "serve_valid",
|
||||
input: "serve /var/www",
|
||||
input: "serve /",
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
@@ -50,6 +50,11 @@ func TestParseCommands(t *testing.T) {
|
||||
input: "serve ",
|
||||
wantErr: ErrInvalidArguments,
|
||||
},
|
||||
{
|
||||
name: "serve_non_exist_path",
|
||||
input: "serve /non-exist-path",
|
||||
wantErr: ErrInvalidArguments,
|
||||
},
|
||||
{
|
||||
name: "serve_too_many_args",
|
||||
input: "serve / / /",
|
||||
|
||||
Reference in New Issue
Block a user