Skip to content

Commit

Permalink
Adding some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie committed Oct 19, 2023
1 parent 71efb78 commit 1525051
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
12 changes: 4 additions & 8 deletions R/sanitise.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-sanitise.R
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 1525051

Please sign in to comment.