-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Improve e2e test setup error reporting
- collect required environment variable checks into one place - report all missing required env-vars instead of just the first failure
- Loading branch information
Showing
6 changed files
with
79 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package setup | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func RequireEnvs(keys ...string) error { | ||
missingEnvs := []string{} | ||
for _, key := range keys { | ||
_, err := GetRequiredEnv(key) | ||
if err != nil { | ||
missingEnvs = append(missingEnvs, key) | ||
} | ||
} | ||
if len(missingEnvs) > 0 { | ||
return fmt.Errorf("missing required env variable(s): %v, cannot continue", missingEnvs) | ||
} | ||
return nil | ||
} | ||
|
||
func GetRequiredEnv(key string) (string, error) { | ||
env := os.Getenv(key) | ||
if env == "" { | ||
return "", fmt.Errorf("\"%s\" env variable is required, cannot continue", key) | ||
} | ||
return env, nil | ||
} |