Skip to content

Commit

Permalink
Tests for provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Dec 7, 2023
1 parent 9144dab commit 47ebdd0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
9 changes: 2 additions & 7 deletions drivers/windows/R/provision.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ windows_provision <- function(method, config, path_root, ...) {
path_lib = config$path_lib,
path_bootstrap = config$path_bootstrap,
...)
windows_provision_run(conan_config, config, path_root)
}


windows_provision_run <- function(conan_config, config, path_root) {
id <- ids::random_id()

path <- file.path(path_root, "hermod", "provision", id, "conan.R")
conan::conan_write(conan_config, path)

path_batch <- write_batch_provision_script(id, hermod_config, path_root)
path_batch <- write_batch_provision_script(id, config, path_root)

path_batch_dat <- prepare_path(path_batch, hermod_config$shares)
path_batch_dat <- prepare_path(path_batch, config$shares)
path_batch_unc <- windows_path(
file.path(path_batch_dat$path_remote, path_batch_dat$rel))

Expand Down
51 changes: 51 additions & 0 deletions drivers/windows/tests/testthat/test-provision.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
test_that("can run provision script", {
mock_client <- list(
submit = mockery::mock("1234"),
status_job = mockery::mock("PENDING", "RUNNING", "RUNNING", "COMPLETE"))
mock_get_client <- mockery::mock(mock_client)
mockery::stub(windows_provision, "get_web_client", mock_get_client)

mount <- withr::local_tempfile()
root <- example_root(mount, "b/c")
file.create(file.path(root$path$root, "provision.R"))

path_root <- root$path$root
config <- root$config$windows

msg <- capture_messages(
windows_provision("script", config, path_root, poll = 0))

mockery::expect_called(mock_get_client, 1)
expect_equal(mockery::mock_args(mock_get_client)[[1]], list())

mockery::expect_called(mock_client$submit, 1)
args <- mockery::mock_args(mock_client$submit)[[1]]
expect_match(args[[2]], "^[[:xdigit:]]{32}$")
id <- args[[2]]
batch_path <- windows_path(file.path(
"//host.dide.ic.ac.uk/share/path/b/c/hermod/provision",
id,
"provision.bat"))
expect_equal(args, list(batch_path, id, "BuildQueue"))

mockery::expect_called(mock_client$status_job, 4)
expect_equal(mockery::mock_args(mock_client$status_job),
rep(list(list("1234")), 4))
})


test_that("error on provision script failure", {
mock_client <- list(
submit = mockery::mock("1234"),
status_job = mockery::mock("PENDING", "RUNNING", "RUNNING", "ERROR"))
mock_get_client <- mockery::mock(mock_client)
mockery::stub(windows_provision, "get_web_client", mock_get_client)
mount <- withr::local_tempfile()
root <- example_root(mount, "b/c")
file.create(file.path(root$path$root, "provision.R"))
path_root <- root$path$root
config <- root$config$windows
expect_error(
suppressMessages(windows_provision("script", config, path_root, poll = 0)),
"Installation failed")
})

0 comments on commit 47ebdd0

Please sign in to comment.