blob: 9eea61f8fd8330099a8462f92e8669a82d25ec12 [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", {
6 expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 1), "No internet|Timeout")
7})
8
Marc Kupietz5d9e3a22020-03-23 09:03:29 +01009test_that("KorAPConnection is printable", {
Marc Kupietza4675722022-02-23 23:55:15 +010010 kco <- new("KorAPConnection", timeout = 10)
11 skip_if(is.null(kco@welcome))
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010012 expect_error(print(kco), NA)
13})
14
Marc Kupietzb2b32a32020-03-24 13:56:50 +010015test_that("Opening KorAPConnection prints some message.", {
16 expect_message(new("KorAPConnection"), "KorAP")
17})
18
Marc Kupietza4675722022-02-23 23:55:15 +010019test_that("Opening KorAPConnection with invalid apiToken fails gracefully", {
20 expect_message(new("KorAPConnection", accessToken="test token", timeout = 10),
21 "401|Timeout")
Marc Kupietzb2b32a32020-03-24 13:56:50 +010022})
23
24test_that("Persisting null apiToken fails", {
Marc Kupietza4675722022-02-23 23:55:15 +010025 kco <- new("KorAPConnection", timeout = 10)
Marc Kupietz5a61f012021-03-04 18:25:27 +010026 skip_if_not(is.null(kco@accessToken))
Marc Kupietza4675722022-02-23 23:55:15 +010027 skip_if(is.null(kco@welcome))
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010028 expect_error(persistAccessToken(kco),
29 ".*not supplied any access token.*",
30 perl = TRUE)
31})
32
33test_that("Opening KorAPConnection with KorAPUrl works", {
Marc Kupietza4675722022-02-23 23:55:15 +010034 kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010035 expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
Marc Kupietza4675722022-02-23 23:55:15 +010036 kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
Marc Kupietz5d9e3a22020-03-23 09:03:29 +010037 expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
38})