Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 1 | test_that("KorAPConnection fails gracefully on unresolvable host", { |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 2 | expect_message(KorAPConnection(accessToken = NULL, apiUrl = "http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve") |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 3 | }) |
| 4 | |
| 5 | test_that("KorAPConnection fails gracefully on timeout", { |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 6 | expect_message(KorAPConnection(apiUrl = "http://httpbin.org/delay/3", accessToken = NULL, timeout = 0.2), "No internet|Timeout|json|progress|Unavailable") |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 7 | }) |
| 8 | |
Marc Kupietz | f650629 | 2023-04-18 07:06:54 +0200 | [diff] [blame] | 9 | test_that("KorAPConnection fails gracefully on Bad Gateway errors", { |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 10 | expect_message(KorAPConnection(apiUrl = "http://httpbin.org/status/502", accessToken = NULL, timeout = 0.5), "No internet|Timeout|progress|json|502") |
Marc Kupietz | f650629 | 2023-04-18 07:06:54 +0200 | [diff] [blame] | 11 | }) |
| 12 | |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 13 | test_that("KorAPConnection is printable", { |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 14 | kco <- KorAPConnection(accessToken = NULL, timeout = 1) |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 15 | skip_if(is.null(kco@welcome)) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 16 | expect_error(print(kco), NA) |
| 17 | }) |
| 18 | |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 19 | test_that("Opening KorAPConnection prints some message.", { |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 20 | expect_message(KorAPConnection(accessToken = NULL), "KorAP") |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 21 | }) |
| 22 | |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 23 | test_that("Opening KorAPConnection with invalid apiToken fails gracefully", { |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 24 | expect_message( |
| 25 | KorAPConnection(accessToken = "test token", timeout = 3), |
| 26 | "401|Timeout|progress" |
| 27 | ) |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 28 | }) |
| 29 | |
| 30 | test_that("Persisting null apiToken fails", { |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 31 | kco <- KorAPConnection(accessToken = NULL, timeout = 3) |
Marc Kupietz | 5a61f01 | 2021-03-04 18:25:27 +0100 | [diff] [blame] | 32 | skip_if_not(is.null(kco@accessToken)) |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 33 | skip_if(is.null(kco@welcome)) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 34 | expect_error(persistAccessToken(kco), |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 35 | ".*not supplied any access token.*", |
| 36 | perl = TRUE |
| 37 | ) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 38 | }) |
| 39 | |
| 40 | test_that("Opening KorAPConnection with KorAPUrl works", { |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 41 | kco <- KorAPConnection(accessToken = NULL, KorAPUrl = "https://korap.ids-mannheim.de", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 42 | expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/")) |
Marc Kupietz | b1dec01 | 2025-06-04 17:16:57 +0200 | [diff] [blame^] | 43 | kco <- KorAPConnection(accessToken = NULL, KorAPUrl = "https://korap.ids-mannheim.de/", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 44 | expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/")) |
| 45 | }) |