Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 1 | test_that("KorAPConnection fails gracefully on unresolvable host", { |
| 2 | expect_message(new("KorAPConnection", apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve") |
| 3 | }) |
| 4 | |
| 5 | test_that("KorAPConnection fails gracefully on timeout", { |
Marc Kupietz | 881c028 | 2023-04-18 15:57:44 +0200 | [diff] [blame^] | 6 | expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 0.2), "No internet|Timeout|json|progress") |
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 | 881c028 | 2023-04-18 15:57:44 +0200 | [diff] [blame^] | 10 | expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/status/502", 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 | 881c028 | 2023-04-18 15:57:44 +0200 | [diff] [blame^] | 14 | kco <- new("KorAPConnection", 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.", { |
| 20 | expect_message(new("KorAPConnection"), "KorAP") |
| 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 | 881c028 | 2023-04-18 15:57:44 +0200 | [diff] [blame^] | 24 | expect_message(new("KorAPConnection", accessToken="test token", timeout = 3), |
| 25 | "401|Timeout|progress") |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 26 | }) |
| 27 | |
| 28 | test_that("Persisting null apiToken fails", { |
Marc Kupietz | 881c028 | 2023-04-18 15:57:44 +0200 | [diff] [blame^] | 29 | kco <- new("KorAPConnection", timeout = 3) |
Marc Kupietz | 5a61f01 | 2021-03-04 18:25:27 +0100 | [diff] [blame] | 30 | skip_if_not(is.null(kco@accessToken)) |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 31 | skip_if(is.null(kco@welcome)) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 32 | expect_error(persistAccessToken(kco), |
| 33 | ".*not supplied any access token.*", |
| 34 | perl = TRUE) |
| 35 | }) |
| 36 | |
| 37 | test_that("Opening KorAPConnection with KorAPUrl works", { |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 38 | kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 39 | expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/")) |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 40 | kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 41 | expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/")) |
| 42 | }) |