test_context.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package framework
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "github.com/onsi/ginkgo/config"
  7. )
  8. type TestContextType struct {
  9. FRPClientPath string
  10. FRPServerPath string
  11. LogLevel string
  12. Debug bool
  13. }
  14. var TestContext TestContextType
  15. // RegisterCommonFlags registers flags common to all e2e test suites.
  16. // The flag set can be flag.CommandLine (if desired) or a custom
  17. // flag set that then gets passed to viperconfig.ViperizeFlags.
  18. //
  19. // The other Register*Flags methods below can be used to add more
  20. // test-specific flags. However, those settings then get added
  21. // regardless whether the test is actually in the test suite.
  22. //
  23. func RegisterCommonFlags(flags *flag.FlagSet) {
  24. // Turn on EmitSpecProgress to get spec progress (especially on interrupt)
  25. config.GinkgoConfig.EmitSpecProgress = true
  26. // Randomize specs as well as suites
  27. config.GinkgoConfig.RandomizeAllSpecs = true
  28. flags.StringVar(&TestContext.FRPClientPath, "frpc-path", "../../bin/frpc", "The frp client binary to use.")
  29. flags.StringVar(&TestContext.FRPServerPath, "frps-path", "../../bin/frps", "The frp server binary to use.")
  30. flags.StringVar(&TestContext.LogLevel, "log-level", "debug", "Log level.")
  31. flags.BoolVar(&TestContext.Debug, "debug", false, "Enable debug mode to print detail info.")
  32. }
  33. func ValidateTestContext(t *TestContextType) error {
  34. if t.FRPClientPath == "" || t.FRPServerPath == "" {
  35. return fmt.Errorf("frpc and frps binary path can't be empty")
  36. }
  37. if _, err := os.Stat(t.FRPClientPath); err != nil {
  38. return fmt.Errorf("load frpc-path error: %v", err)
  39. }
  40. if _, err := os.Stat(t.FRPServerPath); err != nil {
  41. return fmt.Errorf("load frps-path error: %v", err)
  42. }
  43. return nil
  44. }