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", { |
| 6 | expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 1), "No internet|Timeout") |
| 7 | }) |
| 8 | |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 9 | test_that("KorAPConnection is printable", { |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame^] | 10 | kco <- new("KorAPConnection", timeout = 10) |
| 11 | skip_if(is.null(kco@welcome)) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 12 | expect_error(print(kco), NA) |
| 13 | }) |
| 14 | |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 15 | test_that("Opening KorAPConnection prints some message.", { |
| 16 | expect_message(new("KorAPConnection"), "KorAP") |
| 17 | }) |
| 18 | |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame^] | 19 | test_that("Opening KorAPConnection with invalid apiToken fails gracefully", { |
| 20 | expect_message(new("KorAPConnection", accessToken="test token", timeout = 10), |
| 21 | "401|Timeout") |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 22 | }) |
| 23 | |
| 24 | test_that("Persisting null apiToken fails", { |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame^] | 25 | kco <- new("KorAPConnection", timeout = 10) |
Marc Kupietz | 5a61f01 | 2021-03-04 18:25:27 +0100 | [diff] [blame] | 26 | skip_if_not(is.null(kco@accessToken)) |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame^] | 27 | skip_if(is.null(kco@welcome)) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 28 | expect_error(persistAccessToken(kco), |
| 29 | ".*not supplied any access token.*", |
| 30 | perl = TRUE) |
| 31 | }) |
| 32 | |
| 33 | test_that("Opening KorAPConnection with KorAPUrl works", { |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame^] | 34 | kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 35 | 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^] | 36 | kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1) |
Marc Kupietz | 5d9e3a2 | 2020-03-23 09:03:29 +0100 | [diff] [blame] | 37 | expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/")) |
| 38 | }) |