frp/test/e2e/v1/basic/config.go

85 lines
2.1 KiB
Go
Raw Normal View History

2021-06-18 16:48:36 +08:00
package basic
import (
"fmt"
2023-02-27 14:44:16 +08:00
"github.com/onsi/ginkgo/v2"
2022-08-29 01:02:53 +08:00
2021-06-18 16:48:36 +08:00
"github.com/fatedier/frp/test/e2e/framework"
"github.com/fatedier/frp/test/e2e/framework/consts"
"github.com/fatedier/frp/test/e2e/pkg/port"
)
2022-08-29 01:02:53 +08:00
var _ = ginkgo.Describe("[Feature: Config]", func() {
2021-06-18 16:48:36 +08:00
f := framework.NewDefaultFramework()
2022-08-29 01:02:53 +08:00
ginkgo.Describe("Template", func() {
ginkgo.It("render by env", func() {
2021-06-18 16:48:36 +08:00
serverConf := consts.DefaultServerConfig
clientConf := consts.DefaultClientConfig
portName := port.GenName("TCP")
serverConf += fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}"
2021-06-18 16:48:36 +08:00
`, "`", "`")
clientConf += fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
auth.token = "{{ %s{{ .Envs.FRP_TOKEN }}%s }}"
2021-06-18 16:48:36 +08:00
2023-09-13 16:32:39 +08:00
[[proxies]]
name = "tcp"
type = "tcp"
localPort = {{ .%s }}
remotePort = {{ .%s }}
2021-06-18 16:48:36 +08:00
`, "`", "`", framework.TCPEchoServerPort, portName)
f.SetEnvs([]string{"FRP_TOKEN=123"})
f.RunProcesses([]string{serverConf}, []string{clientConf})
framework.NewRequestExpect(f).PortName(portName).Ensure()
})
})
2022-08-29 01:02:53 +08:00
ginkgo.Describe("Includes", func() {
ginkgo.It("split tcp proxies into different files", func() {
2021-06-18 16:48:36 +08:00
serverPort := f.AllocPort()
serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
bindAddr = "0.0.0.0"
bindPort = %d
2021-06-18 16:48:36 +08:00
`, serverPort))
remotePort := f.AllocPort()
proxyConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
[[proxies]]
name = "tcp"
type = "tcp"
localPort = %d
remotePort = %d
2021-06-18 16:48:36 +08:00
`, f.PortByName(framework.TCPEchoServerPort), remotePort))
remotePort2 := f.AllocPort()
proxyConfigPath2 := f.GenerateConfigFile(fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
[[proxies]]
name = "tcp2"
type = "tcp"
localPort = %d
remotePort = %d
2021-06-18 16:48:36 +08:00
`, f.PortByName(framework.TCPEchoServerPort), remotePort2))
clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
2023-09-13 16:32:39 +08:00
serverPort = %d
includes = ["%s","%s"]
2021-06-18 16:48:36 +08:00
`, serverPort, proxyConfigPath, proxyConfigPath2))
_, _, err := f.RunFrps("-c", serverConfigPath)
framework.ExpectNoError(err)
_, _, err = f.RunFrpc("-c", clientConfigPath)
framework.ExpectNoError(err)
framework.NewRequestExpect(f).Port(remotePort).Ensure()
framework.NewRequestExpect(f).Port(remotePort2).Ensure()
})
})
})