-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-get_env_var.R
More file actions
50 lines (34 loc) · 1.31 KB
/
test-get_env_var.R
File metadata and controls
50 lines (34 loc) · 1.31 KB
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
43
44
45
46
47
48
test_that("returns an expected password as if it were from keyring", {
local_mocked_bindings(
get_env_var = function(var_name) {
service = "GLOBAL-SETTING"
username = "keyring_words"
return(list(var_name = service, username = username))
}
)
# Call the function
result <- SQLRtools::get_env_var(var_name = "GLOBAL-SETTING")
# Check the result
expect_equal(result$username, "keyring_words")
expect_equal(result$var_name, "GLOBAL-SETTING")
})
test_that("returns message when not keyring is not set up", {
testthat::expect_error(
get_env_var(var_name = "Something"),
"variable Something not found using keyring or Sys.getenv()"
)
})
test_that("warning if string from Sys.getenv but username is not rstudio-connect", {
withr::local_envvar(c("USERNAME" = "something-connect"))
withr::local_envvar(c("GLOBAL_SETTING" = "system_words"))
expect_warning(
SQLRtools::get_env_var(var_name = "GLOBAL_SETTING"),
"found in Renviron file but not windows credentials"
)
})
test_that("returns string when username is rstudio-connect", {
withr::local_envvar(c("USERNAME" = "rstudio-connect"))
withr::local_envvar(c("GLOBAL_SETTING" = "system_words"))
# Check the result
expect_equal(SQLRtools::get_env_var(var_name = "GLOBAL_SETTING"), "system_words")
})