client.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package basic
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "github.com/fatedier/frp/test/e2e/framework"
  8. "github.com/fatedier/frp/test/e2e/framework/consts"
  9. clientsdk "github.com/fatedier/frp/test/e2e/pkg/sdk/client"
  10. . "github.com/onsi/ginkgo"
  11. )
  12. var _ = Describe("[Feature: ClientManage]", func() {
  13. f := framework.NewDefaultFramework()
  14. It("Update && Reload API", func() {
  15. serverConf := consts.DefaultServerConfig
  16. adminPort := f.AllocPort()
  17. p1Port := f.AllocPort()
  18. p2Port := f.AllocPort()
  19. p3Port := f.AllocPort()
  20. clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
  21. admin_port = %d
  22. [p1]
  23. type = tcp
  24. local_port = {{ .%s }}
  25. remote_port = %d
  26. [p2]
  27. type = tcp
  28. local_port = {{ .%s }}
  29. remote_port = %d
  30. [p3]
  31. type = tcp
  32. local_port = {{ .%s }}
  33. remote_port = %d
  34. `, adminPort,
  35. framework.TCPEchoServerPort, p1Port,
  36. framework.TCPEchoServerPort, p2Port,
  37. framework.TCPEchoServerPort, p3Port)
  38. f.RunProcesses([]string{serverConf}, []string{clientConf})
  39. framework.NewRequestExpect(f).Port(p1Port).Ensure()
  40. framework.NewRequestExpect(f).Port(p2Port).Ensure()
  41. framework.NewRequestExpect(f).Port(p3Port).Ensure()
  42. client := clientsdk.New("127.0.0.1", adminPort)
  43. conf, err := client.GetConfig()
  44. framework.ExpectNoError(err)
  45. newP2Port := f.AllocPort()
  46. // change p2 port and remove p3 proxy
  47. newClientConf := strings.ReplaceAll(conf, strconv.Itoa(p2Port), strconv.Itoa(newP2Port))
  48. p3Index := strings.Index(newClientConf, "[p3]")
  49. newClientConf = newClientConf[:p3Index]
  50. err = client.UpdateConfig(newClientConf)
  51. framework.ExpectNoError(err)
  52. err = client.Reload()
  53. framework.ExpectNoError(err)
  54. time.Sleep(time.Second)
  55. framework.NewRequestExpect(f).Port(p1Port).Explain("p1 port").Ensure()
  56. framework.NewRequestExpect(f).Port(p2Port).Explain("original p2 port").ExpectError(true).Ensure()
  57. framework.NewRequestExpect(f).Port(newP2Port).Explain("new p2 port").Ensure()
  58. framework.NewRequestExpect(f).Port(p3Port).Explain("p3 port").ExpectError(true).Ensure()
  59. })
  60. })