Open PietrH opened 1 month ago
lil :penguin: script to check for these functions:
for(function_to_test in getNamespaceExports("etnservice")) {
test_that(paste(
function_to_test,
"returns same result over api as over local db connection"
),
{
skip_if_offline()
skip("not all functions work with no arguments")
api_result <- do.call(function_to_test, list(api = TRUE))
sql_result <- do.call(function_to_test, list(api = FALSE))
expect_identical(api_result, sql_result, label = function_to_test)
})
}
for(function_to_test in getNamespaceExports("etnservice")){
print(function_to_test)
api_result <- do.call(function_to_test, list(api = TRUE))
sql_result <- do.call(function_to_test, list(api = FALSE))
expect_identical(api_result, sql_result, label = function_to_test)
}
test_result <- purrr::map(
getNamespaceExports("etnservice"),
purrr::safely(function(function_to_test){
api_result <- do.call(function_to_test, list(api = TRUE))
sql_result <- do.call(function_to_test, list(api = FALSE))
expect_identical(api_result, sql_result)
}
)) %>% purrr::set_names(getNamespaceExports("etnservice"))
# only keep those with errors
test_result[purrr::map_lgl(test_result, ~!is.null(purrr::pluck(.x,"error")))]
skip_if(Sys.info()["nodename"] != "rshiny", "Test is not running on Lifewatch RStudio Server")
Or even better:
skip_if("ETN" %in% odbc::odbcListDataSources()$name, "ETN is not a local database on this machine")
During #317 I noticed 9 functions return a different result between the API and a local SQL query.
Some of these differences might be fixed, or at least different after merging #328
API - SQL mismatch
mismatches for:
For example, you could create a
expect_call_agnostic()
, with one argument: a function call. The helper could grab the function call (and its arguments), run it locally and over API and expect the result to be the same.It could then be called as part of a regular test-function.R file: