-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-KorAPConnection.R
42 lines (35 loc) · 1.71 KB
/
test-KorAPConnection.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
test_that("KorAPConnection fails gracefully on unresolvable host", {
expect_message(new("KorAPConnection", apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve")
})
test_that("KorAPConnection fails gracefully on timeout", {
expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", timeout = 1), "No internet|Timeout|json")
})
test_that("KorAPConnection fails gracefully on Bad Gateway errors", {
expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/status/502", timeout = 1), "No internet|Timeout|json|502")
})
test_that("KorAPConnection is printable", {
kco <- new("KorAPConnection", timeout = 10)
skip_if(is.null(kco@welcome))
expect_error(print(kco), NA)
})
test_that("Opening KorAPConnection prints some message.", {
expect_message(new("KorAPConnection"), "KorAP")
})
test_that("Opening KorAPConnection with invalid apiToken fails gracefully", {
expect_message(new("KorAPConnection", accessToken="test token", timeout = 10),
"401|Timeout")
})
test_that("Persisting null apiToken fails", {
kco <- new("KorAPConnection", timeout = 10)
skip_if_not(is.null(kco@accessToken))
skip_if(is.null(kco@welcome))
expect_error(persistAccessToken(kco),
".*not supplied any access token.*",
perl = TRUE)
})
test_that("Opening KorAPConnection with KorAPUrl works", {
kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
kco <- new("KorAPConnection", KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
})