1
0

request.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package framework
  2. import (
  3. "time"
  4. "github.com/fatedier/frp/test/e2e/pkg/request"
  5. )
  6. func ExpectRequest(protocol string, port int, in, out []byte, timeout time.Duration, explain ...interface{}) {
  7. switch protocol {
  8. case "tcp":
  9. ExpectTCPRequest(port, in, out, timeout, explain...)
  10. case "udp":
  11. ExpectUDPRequest(port, in, out, timeout, explain...)
  12. default:
  13. Failf("ExpectRequest not support protocol: %s", protocol)
  14. }
  15. }
  16. func ExpectRequestError(protocol string, port int, in []byte, timeout time.Duration, explain ...interface{}) {
  17. switch protocol {
  18. case "tcp":
  19. ExpectTCPRequestError(port, in, timeout, explain...)
  20. case "udp":
  21. ExpectUDPRequestError(port, in, timeout, explain...)
  22. default:
  23. Failf("ExpectRequestError not support protocol: %s", protocol)
  24. }
  25. }
  26. func ExpectTCPRequest(port int, in, out []byte, timeout time.Duration, explain ...interface{}) {
  27. res, err := request.SendTCPRequest(port, in, timeout)
  28. ExpectNoError(err, explain...)
  29. ExpectEqual(string(out), res, explain...)
  30. }
  31. func ExpectTCPRequestError(port int, in []byte, timeout time.Duration, explain ...interface{}) {
  32. _, err := request.SendTCPRequest(port, in, timeout)
  33. ExpectError(err, explain...)
  34. }
  35. func ExpectUDPRequest(port int, in, out []byte, timeout time.Duration, explain ...interface{}) {
  36. res, err := request.SendUDPRequest(port, in, timeout)
  37. ExpectNoError(err, explain...)
  38. ExpectEqual(string(out), res, explain...)
  39. }
  40. func ExpectUDPRequestError(port int, in []byte, timeout time.Duration, explain ...interface{}) {
  41. _, err := request.SendUDPRequest(port, in, timeout)
  42. ExpectError(err, explain...)
  43. }