From 1525051eec6ce915c61eab3b0f6a7f6793bf537c Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Thu, 19 Oct 2023 09:20:42 +0100 Subject: [PATCH] Adding some tests --- R/sanitise.R | 12 ++++-------- tests/testthat/test-check.R | 5 ++--- tests/testthat/test-sanitise.R | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/test-sanitise.R diff --git a/R/sanitise.R b/R/sanitise.R index e7c1476..7c9e505 100644 --- a/R/sanitise.R +++ b/R/sanitise.R @@ -4,13 +4,9 @@ #' @param audit_connect_check An object from audit.connect::check() #' @export sanitise = function(audit_connect_check) { - user_list = audit_connect_check$users_details$user_list - # Wipe any user-identifiable data: - user_list$users[, "email"] = NA_character_ - user_list$users[, "username"] = NA_character_ - user_list$users[, "first_name"] = NA_character_ - user_list$users[, "last_name"] = NA_character_ - audit_connect_check$users_details$user_list = user_list - # Return the santitized object + # Wipe any user-identifiable data + for (value in c("email", "first_name", "last_name", "username")) { + audit_connect_check$users_details$user_list$users[, value] = NA_character_ + } audit_connect_check } diff --git a/tests/testthat/test-check.R b/tests/testthat/test-check.R index 947dc77..b246ea9 100644 --- a/tests/testthat/test-check.R +++ b/tests/testthat/test-check.R @@ -3,15 +3,14 @@ test_that("High level test", { create_config(default = TRUE) expect_error(check(server = "aaa.bbb")) # Run standard check - rtn = check() + rtn = suppressMessages(check()) expect_true(is.list(rtn)) check_names = c("setup", "posit_version", "server_headers", "feature_usage", "audit_details", "users_details", "versions", "sys_deps", "results") %in% names(rtn) expect_true(all(check_names)) - - expect_equal(ncol(rtn$results), 5) + expect_equal(ncol(rtn$results), 6) # Check Quarto report # Copy over necessary files diff --git a/tests/testthat/test-sanitise.R b/tests/testthat/test-sanitise.R new file mode 100644 index 0000000..2ef08d3 --- /dev/null +++ b/tests/testthat/test-sanitise.R @@ -0,0 +1,17 @@ +describe("Checking sanitize function", { + testthat::skip_on_ci() + # Skip report checks for speed + create_config(default = FALSE, type = "force") + rtn = suppressMessages(check()) + sanitize_rtn = sanitise(rtn) + + it("Check users have been changed", + expect_false(identical(rtn[["users_details"]], + sanitize_rtn[["users_details"]])) + ) + + it("Check everything else has stayed the same", { + rtn[["users_details"]] = sanitize_rtn[["users_details"]] = NULL + expect_identical(rtn, sanitize_rtn) + }) +})