openai/openai-go
Publicmirrored from https://github.com/openai/openai-goAvailable
internal/testutil/testutil.go
27lines · modecode
| 1 | package testutil |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "os" |
| 6 | "strconv" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func CheckTestServer(t *testing.T, url string) bool { |
| 11 | if _, err := http.Get(url); err != nil { |
| 12 | const SKIP_MOCK_TESTS = "SKIP_MOCK_TESTS" |
| 13 | if str, ok := os.LookupEnv(SKIP_MOCK_TESTS); ok { |
| 14 | skip, err := strconv.ParseBool(str) |
| 15 | if err != nil { |
| 16 | t.Fatalf("strconv.ParseBool(os.LookupEnv(%s)) failed: %s", SKIP_MOCK_TESTS, err) |
| 17 | } |
| 18 | if skip { |
| 19 | t.Skip("The test will not run without a mock Prism server running against your OpenAPI spec") |
| 20 | return false |
| 21 | } |
| 22 | 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) |
| 23 | return false |
| 24 | } |
| 25 | } |
| 26 | return true |
| 27 | } |
| 28 | |