Skip to content

Commit

Permalink
Fix tests, incl test for bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Dec 12, 2023
1 parent f7030ac commit 429e570
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
5 changes: 2 additions & 3 deletions drivers/windows/tests/testthat/test-batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ test_that("batch data creates entries for share drives", {
expect_equal(dat$hermod_root_drive, "X:")
expect_equal(dat$hermod_root_path, "\\b\\c")

expected <- sprintf(
"hermod/lib/windows/%s;//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing",
version_string(config$r_version, "."))
v <- version_string(config$r_version, ".")
expected <- sprintf("hermod/lib/windows/%s;I:/bootstrap/%s", v, v)
expect_equal(dat$hermod_library, expected)
})

Expand Down
15 changes: 15 additions & 0 deletions drivers/windows/tests/testthat/test-bootstrap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test_that("can run bootstrap", {
mount <- withr::local_tempfile()
root <- example_root(mount, "b/c")
mock_hermod_provision <- mockery::mock()
mockery::stub(bootstrap_update, "hermod::hermod_provision",
mock_hermod_provision)

bootstrap_update(root)
mockery::expect_called(mock_hermod_provision, 1)
expect_true(file.exists(
file.path(root$path$root, "hermod", "bootstrap-windows.R")))
expect_equal(
mockery::mock_args(mock_hermod_provision)[[1]],
list("script", script = "hermod/bootstrap-windows.R", root = root))
})
3 changes: 1 addition & 2 deletions drivers/windows/tests/testthat/test-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ test_that("Can create configuration", {
expect_equal(config$shares, list(shares))
expect_equal(config$r_version, numeric_version("4.3.0"))
expect_equal(config$path_lib, "hermod/lib/windows/4.3.0")
expect_equal(config$path_bootstrap,
"//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing")
expect_equal(config$path_bootstrap, "I:/bootstrap/4.3.0")
})


Expand Down
9 changes: 5 additions & 4 deletions drivers/windows/tests/testthat/test-provision.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ test_that("can run provision script", {
config <- root$config$windows

msg <- capture_messages(
windows_provision("script", config, path_root, poll = 0))
windows_provision("script", config, path_root, NULL, 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}$")
expect_match(args[[2]], "^conan:[[:xdigit:]]{32}$")
id <- args[[2]]
batch_path <- windows_path(file.path(
"//host.dide.ic.ac.uk/share/path/b/c/hermod/provision",
id,
sub("^conan:", "", id),
"provision.bat"))
expect_equal(args, list(batch_path, id, "BuildQueue"))

Expand All @@ -46,6 +46,7 @@ test_that("error on provision script failure", {
path_root <- root$path$root
config <- root$config$windows
expect_error(
suppressMessages(windows_provision("script", config, path_root, poll = 0)),
suppressMessages(
windows_provision("script", config, path_root, NULL, poll = 0)),
"Installation failed")
})
20 changes: 20 additions & 0 deletions drivers/windows/tests/testthat/test-util.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,23 @@ test_that("readlines from file if exists returns null if file missing", {
writeLines(c("a", "b"), path)
expect_equal(readlines_if_exists(path), c("a", "b"))
})


test_that("writelines_if_not_exists updates files when different", {
path <- withr::local_tempfile()
writelines_if_different(c("a", "b"), path)
expect_equal(readLines(path), c("a", "b"))

writelines_if_different(c("a", "b", "c"), path)
expect_equal(readLines(path), c("a", "b", "c"))
})


test_that("writelines_if_not_exists does not update file when not different", {
path <- withr::local_tempfile()
writeLines(c("a", "b"), path)
mock_writelines <- mockery::mock()
mockery::stub(writelines_if_different, "writeLines", mock_writelines)
writelines_if_different(c("a", "b"), path)
mockery::expect_called(mock_writelines, 0)
})

0 comments on commit 429e570

Please sign in to comment.