Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): avoid test failures when SKIP_MOCK_TESTS is not set #85

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (

func CheckTestServer(t *testing.T, url string) bool {
if _, err := http.Get(url); err != nil {
str := os.Getenv("SKIP_MOCK_TESTS")
skip, err := strconv.ParseBool(str)
if err != nil {
panic("invalid value for flag SKIP_MOCK_TESTS \"" + str + "\", should be parsable as a bool")
}
if skip {
t.Skip("The test will not run without a mock Prism server running against your OpenAPI spec")
const SKIP_MOCK_TESTS = "SKIP_MOCK_TESTS"
if str, ok := os.LookupEnv(SKIP_MOCK_TESTS); ok {
skip, err := strconv.ParseBool(str)
if err != nil {
t.Fatalf("strconv.ParseBool(os.LookupEnv(%s)) failed: %s", SKIP_MOCK_TESTS, err)
}
if skip {
t.Skip("The test will not run without a mock Prism server running against your OpenAPI spec")
return false
}
t.Errorf("The test will not run without a mock Prism server running against your OpenAPI spec. You can set the environment variable %s to true to skip running any tests that require the mock server", SKIP_MOCK_TESTS)
return false
}
t.Error("The test will not run without a mock Prism server running against your OpenAPI spec. You can set the environment variable SKIP_MOCK_TESTS to true to skip running any tests that require the mock server.")
return false
}
return true
}