blob: eea2265b825795a42d972ff2c1adacd3f9f358fc [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 Kupietz881c0282023-04-18 15:57:44 +02006 expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 0.2), "No internet|Timeout|json|progress")
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", {
Marc Kupietz881c0282023-04-18 15:57:44 +020010 expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/status/502", timeout = 0.5), "No internet|Timeout|progress|json|502")
Marc Kupietzf6506292023-04-18 07:06:54 +020011})
12
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010013test_that("KorAPConnection is printable", {
Marc Kupietz881c0282023-04-18 15:57:44 +020014 kco <- new("KorAPConnection", timeout = 1)
Marc Kupietza4675722022-02-23 23:55:15 +010015 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", {
Marc Kupietz881c0282023-04-18 15:57:44 +020024 expect_message(new("KorAPConnection", accessToken="test token", timeout = 3),
25 "401|Timeout|progress")
Marc Kupietzb2b32a32020-03-24 13:56:50 +010026})
27
28test_that("Persisting null apiToken fails", {
Marc Kupietz881c0282023-04-18 15:57:44 +020029 kco <- new("KorAPConnection", timeout = 3)
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})