config.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package basic
  2. import (
  3. "fmt"
  4. "github.com/fatedier/frp/test/e2e/framework"
  5. "github.com/fatedier/frp/test/e2e/framework/consts"
  6. "github.com/fatedier/frp/test/e2e/pkg/port"
  7. . "github.com/onsi/ginkgo"
  8. )
  9. var _ = Describe("[Feature: Config]", func() {
  10. f := framework.NewDefaultFramework()
  11. Describe("Template", func() {
  12. It("render by env", func() {
  13. serverConf := consts.DefaultServerConfig
  14. clientConf := consts.DefaultClientConfig
  15. portName := port.GenName("TCP")
  16. serverConf += fmt.Sprintf(`
  17. token = {{ %s{{ .Envs.FRP_TOKEN }}%s }}
  18. `, "`", "`")
  19. clientConf += fmt.Sprintf(`
  20. token = {{ %s{{ .Envs.FRP_TOKEN }}%s }}
  21. [tcp]
  22. type = tcp
  23. local_port = {{ .%s }}
  24. remote_port = {{ .%s }}
  25. `, "`", "`", framework.TCPEchoServerPort, portName)
  26. f.SetEnvs([]string{"FRP_TOKEN=123"})
  27. f.RunProcesses([]string{serverConf}, []string{clientConf})
  28. framework.NewRequestExpect(f).PortName(portName).Ensure()
  29. })
  30. })
  31. Describe("Includes", func() {
  32. It("split tcp proxies into different files", func() {
  33. serverPort := f.AllocPort()
  34. serverConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
  35. [common]
  36. bind_addr = 0.0.0.0
  37. bind_port = %d
  38. `, serverPort))
  39. remotePort := f.AllocPort()
  40. proxyConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
  41. [tcp]
  42. type = tcp
  43. local_port = %d
  44. remote_port = %d
  45. `, f.PortByName(framework.TCPEchoServerPort), remotePort))
  46. remotePort2 := f.AllocPort()
  47. proxyConfigPath2 := f.GenerateConfigFile(fmt.Sprintf(`
  48. [tcp2]
  49. type = tcp
  50. local_port = %d
  51. remote_port = %d
  52. `, f.PortByName(framework.TCPEchoServerPort), remotePort2))
  53. clientConfigPath := f.GenerateConfigFile(fmt.Sprintf(`
  54. [common]
  55. server_port = %d
  56. includes = %s,%s
  57. `, serverPort, proxyConfigPath, proxyConfigPath2))
  58. _, _, err := f.RunFrps("-c", serverConfigPath)
  59. framework.ExpectNoError(err)
  60. _, _, err = f.RunFrpc("-c", clientConfigPath)
  61. framework.ExpectNoError(err)
  62. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  63. framework.NewRequestExpect(f).Port(remotePort2).Ensure()
  64. })
  65. })
  66. })