diff --git a/.gitignore b/.gitignore index efe8a28..bc7fa61 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ go.work # the produced binary report.xml errors/ -vitess-tester \ No newline at end of file +vitess-tester + +# Do not ignore anything inside the src/vitess-tester directory +!/src/vitess-tester/ \ No newline at end of file diff --git a/main.go b/main.go index f5930a2..0a8f2df 100644 --- a/main.go +++ b/main.go @@ -205,6 +205,13 @@ func main() { flag.Parse() tests := flag.Args() + err := vitess_tester.CheckEnvironment() + if err != nil { + fmt.Println("Fatal error:") + fmt.Println(err.Error()) + os.Exit(1) + } + if ll := os.Getenv("LOG_LEVEL"); ll != "" { logLevel = ll } @@ -227,7 +234,7 @@ func main() { defer closer() // remove errors folder if exists - err := os.RemoveAll("errors") + err = os.RemoveAll("errors") if err != nil { panic(err.Error()) } diff --git a/src/vitess-tester/environment.go b/src/vitess-tester/environment.go new file mode 100644 index 0000000..2a48ab1 --- /dev/null +++ b/src/vitess-tester/environment.go @@ -0,0 +1,50 @@ +/* +Copyright 2024 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package vitess_tester + +import ( + "fmt" + "os" + "os/exec" +) + +var environmentVars = []string{ + "VTDATAROOT", + "VTROOT", +} +var neededBinaries = []string{ + "vtgate", + "mysqlctl", +} + +// CheckEnvironment checks if the required environment variables are set +func CheckEnvironment() error { + for _, envVar := range environmentVars { + if os.Getenv(envVar) == "" { + return fmt.Errorf("environment variable %s is not set\nTry sourcing the dev.env file in the vitess directory", envVar) + } + } + + for _, binary := range neededBinaries { + _, err := exec.LookPath(binary) + if err != nil { + return fmt.Errorf("binary %s not found in PATH", binary) + } + } + + return nil +}