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