blob: a1efd9e7831b45eaebf4476c97143726748aade2 [file] [log] [blame]
Marc Kupietza4675722022-02-23 23:55:15 +01001test_that("KorAPConnection fails gracefully on unresolvable host", {
2 expect_message(new("KorAPConnection", apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve")
3})
4
5test_that("KorAPConnection fails gracefully on timeout", {
Marc Kupietz9cdb4be2023-04-17 19:20:09 +02006 expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 1), "No internet|Timeout|json")
Marc Kupietza4675722022-02-23 23:55:15 +01007})
8
Marc Kupietzf6506292023-04-18 07:06:54 +02009test_that("KorAPConnection fails gracefully on Bad Gateway errors", {
10 expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/status/502", timeout = 1), "No internet|Timeout|json|502")
11})
12
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010013test_that("KorAPConnection is printable", {
Marc Kupietza4675722022-02-23 23:55:15 +010014 kco <- new("KorAPConnection", timeout = 10)
15 skip_if(is.null(kco@welcome))
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010016 expect_error(print(kco), NA)
17})
18
Marc Kupietzb2b32a32020-03-24 13:56:50 +010019test_that("Opening KorAPConnection prints some message.", {
20 expect_message(new("KorAPConnection"), "KorAP")
21})
22
Marc Kupietza4675722022-02-23 23:55:15 +010023test_that("Opening KorAPConnection with invalid apiToken fails gracefully", {
24 expect_message(new("KorAPConnection", accessToken="test token", timeout = 10),
25 "401|Timeout")
Marc Kupietzb2b32a32020-03-24 13:56:50 +010026})
27
28test_that("Persisting null apiToken fails", {
Marc Kupietza4675722022-02-23 23:55:15 +010029 kco <- new("KorAPConnection", timeout = 10)
Marc Kupietz5a61f012021-03-04 18:25:27 +010030 skip_if_not(is.null(kco@accessToken))
Marc Kupietza4675722022-02-23 23:55:15 +010031 skip_if(is.null(kco@welcome))
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010032 expect_error(persistAccessToken(kco),
33 ".*not supplied any access token.*",
34 perl = TRUE)
35})
36
37test_that("Opening KorAPConnection with KorAPUrl works", {
Marc Kupietza4675722022-02-23 23:55:15 +010038 kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010039 expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
Marc Kupietza4675722022-02-23 23:55:15 +010040 kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010041 expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
42})