test_context.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package framework
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. )
  7. type TestContextType struct {
  8. FRPClientPath string
  9. FRPServerPath string
  10. LogLevel string
  11. }
  12. var TestContext TestContextType
  13. // RegisterCommonFlags registers flags common to all e2e test suites.
  14. // The flag set can be flag.CommandLine (if desired) or a custom
  15. // flag set that then gets passed to viperconfig.ViperizeFlags.
  16. //
  17. // The other Register*Flags methods below can be used to add more
  18. // test-specific flags. However, those settings then get added
  19. // regardless whether the test is actually in the test suite.
  20. //
  21. func RegisterCommonFlags(flags *flag.FlagSet) {
  22. flags.StringVar(&TestContext.FRPClientPath, "frpc-path", "../../bin/frpc", "The frp client binary to use.")
  23. flags.StringVar(&TestContext.FRPServerPath, "frps-path", "../../bin/frps", "The frp server binary to use.")
  24. flags.StringVar(&TestContext.LogLevel, "log-level", "debug", "Log level.")
  25. }
  26. func ValidateTestContext(t *TestContextType) error {
  27. if t.FRPClientPath == "" || t.FRPServerPath == "" {
  28. return fmt.Errorf("frpc and frps binary path can't be empty")
  29. }
  30. if _, err := os.Stat(t.FRPClientPath); err != nil {
  31. return fmt.Errorf("load frpc-path error: %v", err)
  32. }
  33. if _, err := os.Stat(t.FRPServerPath); err != nil {
  34. return fmt.Errorf("load frps-path error: %v", err)
  35. }
  36. return nil
  37. }