From c8d2bfc0237554bb4db96e65fcf9b434da1bb791 Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 8 Jan 2026 10:45:30 +0100 Subject: [PATCH 1/7] Make tests flexible for new year --- tests/testthat/test-get_vpts_coverage_rmi.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_vpts_coverage_rmi.R b/tests/testthat/test-get_vpts_coverage_rmi.R index 36319c44..37015049 100644 --- a/tests/testthat/test-get_vpts_coverage_rmi.R +++ b/tests/testthat/test-get_vpts_coverage_rmi.R @@ -41,7 +41,7 @@ test_that("get_vpts_coverage_rmi() returns known radars and years", { expect_in( lubridate::year(cov$date), - seq(2019, 2025) + seq(2019, lubridate::year(Sys.Date())) ) }) From f58d1a59a269cd19dec41f723bb1e6db3481bf27 Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 8 Jan 2026 11:05:33 +0100 Subject: [PATCH 2/7] More files present now --- tests/testthat/test-get_pvol_ro.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_pvol_ro.R b/tests/testthat/test-get_pvol_ro.R index b52a7368..b5822d97 100644 --- a/tests/testthat/test-get_pvol_ro.R +++ b/tests/testthat/test-get_pvol_ro.R @@ -11,7 +11,8 @@ test_that("Check if the available attributes changed", { unique() |> gsub(pattern = ".hdf", replacement = "") |> sort(), - c("KDP", "RhoHV", "V", "ZDR", "dBZ") |> sort() + c("Height", "KDP", "RhoHV", "V", "ZDR", "dBR", "dBZ") |> sort() + # Height and dBR are none polar files ) }) test_that("Pvol for Romania can be downloaded", { From c467048152bf2053082605442ef5b1a038dc8d8a Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 13 Jan 2026 14:49:41 +0100 Subject: [PATCH 3/7] remove duplicated test --- tests/testthat/test-get_pvol_nl.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/testthat/test-get_pvol_nl.R b/tests/testthat/test-get_pvol_nl.R index 783bbd65..cfb08d89 100644 --- a/tests/testthat/test-get_pvol_nl.R +++ b/tests/testthat/test-get_pvol_nl.R @@ -13,10 +13,6 @@ test_that("Pvol for the Netherlands can be downloaded", { ) ) time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") - expect_s3_class( - get_pvol("nlhrw", time, param = "all"), - "pvol" - ) pvol <- expect_s3_class(get_pvol("nlhrw", time, param = "all"), "pvol") expect_true(bioRad::is.pvol(pvol)) expect_identical( From 192a3c3ee2fa174782af59b81fd8465813ac499c Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 13 Jan 2026 17:45:52 +0100 Subject: [PATCH 4/7] try secret key --- .github/workflows/R-CMD-check.yaml | 1 + tests/testthat/test-get_pvol_nl.R | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0cb35935..aa141bdc 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,6 +29,7 @@ jobs: - {os: ubuntu-latest, r: '4.1.0'} env: + getrad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes diff --git a/tests/testthat/test-get_pvol_nl.R b/tests/testthat/test-get_pvol_nl.R index cfb08d89..e1b77ecc 100644 --- a/tests/testthat/test-get_pvol_nl.R +++ b/tests/testthat/test-get_pvol_nl.R @@ -30,12 +30,6 @@ test_that("Pvol for the Netherlands can be downloaded. Incorrect converter resul "keyring_backend" = "env", "getRad.nl_converter" = "ls" )) - # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token - withr::local_envvar( - list( - "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" - ) - ) time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") expect_error( get_pvol("nlhrw", time, param = "all"), From 7e36ba5c64c26b48f1887f70ffb13201a6b006d2 Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 13 Jan 2026 18:26:18 +0100 Subject: [PATCH 5/7] typo --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index aa141bdc..f67292d2 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,7 +29,7 @@ jobs: - {os: ubuntu-latest, r: '4.1.0'} env: - getrad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes From a95e60b7316732f567294d7c2fdec61a0b725319 Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 13 Jan 2026 19:00:11 +0100 Subject: [PATCH 6/7] Make sure there is a fall back on the anonymous key and use the secret in regular checks --- .github/workflows/regular-checks.yaml | 1 + tests/testthat/test-get_pvol_nl.R | 40 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/regular-checks.yaml b/.github/workflows/regular-checks.yaml index 8967ac53..5c8cbc5a 100644 --- a/.github/workflows/regular-checks.yaml +++ b/.github/workflows/regular-checks.yaml @@ -22,6 +22,7 @@ jobs: - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} env: + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes diff --git a/tests/testthat/test-get_pvol_nl.R b/tests/testthat/test-get_pvol_nl.R index e1b77ecc..f753e63f 100644 --- a/tests/testthat/test-get_pvol_nl.R +++ b/tests/testthat/test-get_pvol_nl.R @@ -2,16 +2,21 @@ test_that("Pvol for the Netherlands can be downloaded", { skip_if(Sys.which("KNMI_vol_h5_to_ODIM_h5") == "") skip_if_offline(host = "api.dataplatform.knmi.nl") - # make sure local env is used by keyring so that api key can be set - withr::local_options(list( - "keyring_backend" = "env" - )) - # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token - withr::local_envvar( - list( - "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + # First see if a key can be retrieved if not make sure env is used as a keyring backend + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + withr::local_options(list( + "keyring_backend" = "env" + )) + } + # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token + withr::local_envvar( + list( + "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + ) ) - ) + } time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") pvol <- expect_s3_class(get_pvol("nlhrw", time, param = "all"), "pvol") expect_true(bioRad::is.pvol(pvol)) @@ -27,9 +32,24 @@ test_that("Pvol for the Netherlands can be downloaded. Incorrect converter resul # make sure local env is used by keyring so that api key can be set withr::local_options(list( - "keyring_backend" = "env", "getRad.nl_converter" = "ls" )) + + # First see if a key can be retrieved if not make sure env is used as a keyring backend + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + withr::local_options(list( + "keyring_backend" = "env" + )) + } + # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token + withr::local_envvar( + list( + "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + ) + ) + } time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") expect_error( get_pvol("nlhrw", time, param = "all"), From 3840f333a55f9aa40d7c6144d3b7c5d42532978e Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 13 Jan 2026 19:17:21 +0100 Subject: [PATCH 7/7] make tests work again --- .github/workflows/test-coverage.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 0ab748d6..1d28b2b8 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -13,6 +13,7 @@ jobs: test-coverage: runs-on: ubuntu-latest env: + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: