tests/testthat/test-cff-gha-update.R

test_that("cff_gha_update installs a workflow in the requested package", {
  skip_on_cran()

  new_dir <- local_mock_package(
    description = "DESCRIPTION_many_urls",
    rbuildignore = TRUE,
    local_dir = FALSE
  )
  rbuildignore <- file.path(new_dir, ".Rbuildignore")
  expect_true(file.exists(rbuildignore))

  # Add action
  expect_message(cff_gha_update(path = new_dir), "Creating directory")

  expect_message(cff_gha_update(path = new_dir), "already exists")
  expect_message(
    cff_gha_update(path = new_dir, overwrite = TRUE),
    "Workflow installed"
  )

  expect_true(file.exists(file.path(
    new_dir,
    ".github",
    "workflows",
    "update-citation-cff.yaml"
  )))

  expect_true("^\\.github$" %in% readLines(rbuildignore))
})

test_that("cff_gha_update errors when workflow copy fails", {
  skip_on_cran()

  new_dir <- local_mock_package(
    description = "DESCRIPTION_many_urls",
    rbuildignore = TRUE,
    local_dir = FALSE
  )

  local_mocked_bindings(cff_copy_workflow = function(from, to, overwrite) FALSE)

  expect_snapshot(
    cff_gha_update(path = new_dir),
    error = TRUE,
    transform = \(lines) gsub(new_dir, "<package>", lines, fixed = TRUE)
  )
})

Try the cffr package in your browser

Any scripts or data that you put into this service are public.

cffr documentation built on Aug. 24, 2026, 5:11 p.m.