github.com/anthropics/anthropic-sdk-go@v1.70.1/internal/testutil/testutil.go (about) 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 server running against your OpenAPI spec") 20 return false 21 } 22 t.Errorf("The test will not run without a mock 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 }