mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 07:35:07 +00:00
support range ports mapping by go template (#4073)
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
clientsdk "github.com/fatedier/frp/pkg/sdk/client"
|
||||
"github.com/fatedier/frp/test/e2e/framework"
|
||||
"github.com/fatedier/frp/test/e2e/framework/consts"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/request"
|
||||
@@ -57,7 +56,7 @@ var _ = ginkgo.Describe("[Feature: ClientManage]", func() {
|
||||
framework.NewRequestExpect(f).Port(p2Port).Ensure()
|
||||
framework.NewRequestExpect(f).Port(p3Port).Ensure()
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
client := f.APIClientForFrpc(adminPort)
|
||||
conf, err := client.GetConfig()
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
@@ -124,7 +123,7 @@ var _ = ginkgo.Describe("[Feature: ClientManage]", func() {
|
||||
|
||||
framework.NewRequestExpect(f).Port(testPort).Ensure()
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
client := f.APIClientForFrpc(adminPort)
|
||||
err := client.Stop()
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
|
@@ -38,6 +38,51 @@ var _ = ginkgo.Describe("[Feature: Config]", func() {
|
||||
|
||||
framework.NewRequestExpect(f).PortName(portName).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("Range ports mapping", func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
clientConf := consts.DefaultClientConfig
|
||||
|
||||
adminPort := f.AllocPort()
|
||||
|
||||
localPortsRange := "13010-13012,13014"
|
||||
remotePortsRange := "23010-23012,23014"
|
||||
escapeTemplate := func(s string) string {
|
||||
return "{{ `" + s + "` }}"
|
||||
}
|
||||
clientConf += fmt.Sprintf(`
|
||||
webServer.port = %d
|
||||
|
||||
%s
|
||||
[[proxies]]
|
||||
name = "tcp-%s"
|
||||
type = "tcp"
|
||||
localPort = %s
|
||||
remotePort = %s
|
||||
%s
|
||||
`, adminPort,
|
||||
escapeTemplate(fmt.Sprintf(`{{- range $_, $v := parseNumberRangePair "%s" "%s" }}`, localPortsRange, remotePortsRange)),
|
||||
escapeTemplate("{{ $v.First }}"),
|
||||
escapeTemplate("{{ $v.First }}"),
|
||||
escapeTemplate("{{ $v.Second }}"),
|
||||
escapeTemplate("{{- end }}"),
|
||||
)
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
client := f.APIClientForFrpc(adminPort)
|
||||
checkProxyFn := func(name string, localPort, remotePort int) {
|
||||
status, err := client.GetProxyStatus(name)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
framework.ExpectContainSubstring(status.LocalAddr, fmt.Sprintf(":%d", localPort))
|
||||
framework.ExpectContainSubstring(status.RemoteAddr, fmt.Sprintf(":%d", remotePort))
|
||||
}
|
||||
checkProxyFn("tcp-13010", 13010, 23010)
|
||||
checkProxyFn("tcp-13011", 13011, 23011)
|
||||
checkProxyFn("tcp-13012", 13012, 23012)
|
||||
checkProxyFn("tcp-13014", 13014, 23014)
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.Describe("Includes", func() {
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
clientsdk "github.com/fatedier/frp/pkg/sdk/client"
|
||||
"github.com/fatedier/frp/test/e2e/framework"
|
||||
"github.com/fatedier/frp/test/e2e/framework/consts"
|
||||
"github.com/fatedier/frp/test/e2e/pkg/port"
|
||||
@@ -110,7 +109,7 @@ var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||
|
||||
client := clientsdk.New("127.0.0.1", adminPort)
|
||||
client := f.APIClientForFrpc(adminPort)
|
||||
|
||||
// tcp random port
|
||||
status, err := client.GetProxyStatus("tcp")
|
||||
|
Reference in New Issue
Block a user