From 83b8c743564d7169a9091d040adbdb230ce9192a Mon Sep 17 00:00:00 2001 From: eblondel Date: Thu, 2 Jan 2025 22:29:38 +0100 Subject: [PATCH] inspire tests --- .../testthat/test_INSPIREMetadataValidator.R | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test_INSPIREMetadataValidator.R b/tests/testthat/test_INSPIREMetadataValidator.R index c5049277..48f18a50 100644 --- a/tests/testthat/test_INSPIREMetadataValidator.R +++ b/tests/testthat/test_INSPIREMetadataValidator.R @@ -19,16 +19,20 @@ test_that("inspire - metadata validator",{ apiKey <- Sys.getenv("INSPIRE_API_KEY") if(nzchar(apiKey)){ inspireValidator <- INSPIREMetadataValidator$new(url = Sys.getenv("INSPIRE_API_ENDPOINT"), apiKey = apiKey) - inspireReport <- inspireValidator$getValidationReport(obj = md, raw = TRUE) - if(inspireValidator$running){ - expect_is(inspireReport, "list") - expect_equal(names(inspireReport), c("Status","Completeness","Test Run ID","Log", "Ref URI", "HTML Report", "raw")) - }else{ - expect_null(inspireReport) + if(!is.null(inspireValidator)){ + inspireReport <- inspireValidator$getValidationReport(obj = md, raw = TRUE) + if(inspireValidator$running){ + expect_is(inspireReport, "list") + expect_equal(names(inspireReport), c("Status","Completeness","Test Run ID","Log", "Ref URI", "HTML Report", "raw")) + }else{ + expect_null(inspireReport) + } } }else{ inspireValidator <- INSPIREMetadataValidator$new(url = Sys.getenv("INSPIRE_API_ENDPOINT"), apiKey = apiKey) - expect_error(inspireValidator$getValidationReport(obj = md, raw = TRUE)) + if(!is.null(inspireValidator)){ + expect_error(inspireValidator$getValidationReport(obj = md, raw = TRUE)) + } } }) @@ -37,7 +41,7 @@ test_that("inspire - metadata validator 'encode' shortcut",{ apiKey <- Sys.getenv("INSPIRE_API_KEY") if(nzchar(apiKey)){ inspireValidator <- INSPIREMetadataValidator$new(url = Sys.getenv("INSPIRE_API_ENDPOINT"), apiKey = apiKey) - xml <- md$encode(inspire = TRUE, inspireValidator = inspireValidator) + if(!is.null(inspireValidator)) xml <- md$encode(inspire = TRUE, inspireValidator = inspireValidator) } }) @@ -46,6 +50,6 @@ test_that("inspire - metadata validator 'save' shortcut",{ apiKey <- Sys.getenv("INSPIRE_API_KEY") if(nzchar(apiKey)){ inspireValidator <- INSPIREMetadataValidator$new(url = Sys.getenv("INSPIRE_API_ENDPOINT"), apiKey = apiKey) - md$save("my-metadata.xml", inspire = TRUE, inspireValidator = inspireValidator) + if(!is.null(inspireValidator)) md$save("my-metadata.xml", inspire = TRUE, inspireValidator = inspireValidator) } }) \ No newline at end of file