testutil.go 801 B

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