annotations.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package basic
  2. import (
  3. "fmt"
  4. "io"
  5. "net/http"
  6. "github.com/onsi/ginkgo/v2"
  7. "github.com/tidwall/gjson"
  8. "github.com/fatedier/frp/test/e2e/framework"
  9. "github.com/fatedier/frp/test/e2e/framework/consts"
  10. )
  11. var _ = ginkgo.Describe("[Feature: Annotations]", func() {
  12. f := framework.NewDefaultFramework()
  13. ginkgo.It("Set Proxy Annotations", func() {
  14. webPort := f.AllocPort()
  15. serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
  16. webServer.port = %d
  17. `, webPort)
  18. p1Port := f.AllocPort()
  19. clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
  20. [[proxies]]
  21. name = "p1"
  22. type = "tcp"
  23. localPort = {{ .%s }}
  24. remotePort = %d
  25. [proxies.annotations]
  26. "frp.e2e.test/foo" = "value1"
  27. "frp.e2e.test/bar" = "value2"
  28. `, framework.TCPEchoServerPort, p1Port)
  29. f.RunProcesses([]string{serverConf}, []string{clientConf})
  30. framework.NewRequestExpect(f).Port(p1Port).Ensure()
  31. // check annotations in frps
  32. resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/api/proxy/tcp/%s", webPort, "p1"))
  33. framework.ExpectNoError(err)
  34. framework.ExpectEqual(resp.StatusCode, 200)
  35. defer resp.Body.Close()
  36. content, err := io.ReadAll(resp.Body)
  37. framework.ExpectNoError(err)
  38. annotations := gjson.Get(string(content), "conf.annotations").Map()
  39. framework.ExpectEqual("value1", annotations["frp.e2e.test/foo"].String())
  40. framework.ExpectEqual("value2", annotations["frp.e2e.test/bar"].String())
  41. })
  42. })