Tests: setup and check keyring
Change-Id: I9b71d0b3ee486f403dc72abcc67c2104627f9cd4
diff --git a/tests/testthat/setup-keyring.R b/tests/testthat/setup-keyring.R
new file mode 100644
index 0000000..7e06933
--- /dev/null
+++ b/tests/testthat/setup-keyring.R
@@ -0,0 +1,13 @@
+# Setup keyring for testing
+if (requireNamespace("keyring", quietly = TRUE)) {
+ # Set environment variables to use a non-interactive keyring backend
+ # This prevents password prompts during testing
+ if (!nzchar(Sys.getenv("KEYRING_BACKEND"))) {
+ Sys.setenv("KEYRING_BACKEND" = "env")
+ }
+
+ # Alternatively, if env backend doesn't work, try file backend with empty password
+ if (!nzchar(Sys.getenv("KEYRING_PASS"))) {
+ Sys.setenv("KEYRING_PASS" = "")
+ }
+}
diff --git a/tests/testthat/test-KorAPConnection.R b/tests/testthat/test-KorAPConnection.R
index 3ee7bb7..9a52c46 100644
--- a/tests/testthat/test-KorAPConnection.R
+++ b/tests/testthat/test-KorAPConnection.R
@@ -54,6 +54,18 @@
test_that("persistAccessToken works with valid token", {
skip_if_not_installed("keyring")
+
+ # Test keyring functionality - skip if keyring setup fails
+ keyring_available <- tryCatch({
+ # Try to access keyring backend
+ keyring::default_backend()
+ TRUE
+ }, error = function(e) {
+ FALSE
+ })
+
+ skip_if(!keyring_available, "Keyring not properly configured for testing")
+
kco <- KorAPConnection(accessToken = NULL, timeout = 1)
test_token <- "test_access_token_123"
@@ -61,7 +73,6 @@
expect_true(is.function(persistAccessToken))
# Test that we can call the function with a token
- # This will test the function logic without relying on keyring
expect_error(persistAccessToken(kco, accessToken = test_token), NA)
})
@@ -76,6 +87,18 @@
test_that("clearAccessToken removes token", {
skip_if_not_installed("keyring")
+
+ # Test keyring functionality - skip if keyring setup fails
+ keyring_available <- tryCatch({
+ # Try to access keyring backend
+ keyring::default_backend()
+ TRUE
+ }, error = function(e) {
+ FALSE
+ })
+
+ skip_if(!keyring_available, "Keyring not properly configured for testing")
+
kco <- KorAPConnection(accessToken = "test_token", timeout = 1)
# Test that clearAccessToken function exists and is callable