Make sure to always fail gracefully if server not accessible

See CRAN policy:

Packages which use Internet resources should fail gracefully with an informative message
if the resource is not available or has changed (and not give a check warning nor error).

at https://cran.r-project.org/web/packages/policies.html

Change-Id: I0c346c75786b8f5392694337254d6f19f91d7caf
diff --git a/tests/testthat/test-KorAPConnection.R b/tests/testthat/test-KorAPConnection.R
index c96805d..9eea61f 100644
--- a/tests/testthat/test-KorAPConnection.R
+++ b/tests/testthat/test-KorAPConnection.R
@@ -1,5 +1,14 @@
+test_that("KorAPConnection fails gracefully on unresolvable host", {
+  expect_message(new("KorAPConnection", apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve")
+})
+
+test_that("KorAPConnection fails gracefully on timeout", {
+  expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 1), "No internet|Timeout")
+})
+
 test_that("KorAPConnection is printable", {
-  kco <- new("KorAPConnection")
+  kco <- new("KorAPConnection", timeout = 10)
+  skip_if(is.null(kco@welcome))
   expect_error(print(kco), NA)
 })
 
@@ -7,22 +16,23 @@
   expect_message(new("KorAPConnection"), "KorAP")
 })
 
-test_that("Opening KorAPConnection with invalid apiToken fails", {
-  expect_error(new("KorAPConnection", accessToken="test token"),
-               "401")
+test_that("Opening KorAPConnection with invalid apiToken fails gracefully", {
+  expect_message(new("KorAPConnection", accessToken="test token", timeout = 10),
+               "401|Timeout")
 })
 
 test_that("Persisting null apiToken fails", {
-  kco <- new("KorAPConnection")
+  kco <- new("KorAPConnection", timeout = 10)
   skip_if_not(is.null(kco@accessToken))
+  skip_if(is.null(kco@welcome))
   expect_error(persistAccessToken(kco),
                ".*not supplied any access token.*",
                perl = TRUE)
 })
 
 test_that("Opening KorAPConnection with KorAPUrl works", {
-  kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de")
+  kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
   expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
-  kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/")
+  kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
   expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
 })