tests/testthat/test-update-yaml.R

# GitHub Actions ---------------------------------------------------------------

test_that("update_yml() preserves custom env vars AND blocks", {
  create_local_package()
  update_yml(
    system.file("testdata/ghactions-test-update-yaml-env-and-blocks.yml", package = "tic"), # nolint
    paste0(tempdir(), "/test-update-yaml-env-and-blocks-updated.yml")
  )

  updated <- readLines(paste0(tempdir(), "/test-update-yaml-env-and-blocks-updated.yml")) # nolint
  solution <- readLines(system.file("testdata/ghactions-test-update-yaml-env-and-blocks-solution.yml", package = "tic")) # nolint
  expect_equal(updated, solution)
})

test_that("update_yml() fails with descriptive error message if diffs between
          local and upstream template are too large", {
  create_local_package()
  expect_error(
    update_yml(
      system.file("testdata/ghactions-check-update-fail.yml", package = "tic"), # nolint
    ),
    "Not enough valid anchors points found between local and upstream template."
  )
})

# Circle CI --------------------------------------------------------------------

test_that("update_yml() preserves custom env vars AND blocks - Circle CI", {
  create_local_package()
  update_yml(
    system.file("testdata/circle-test-update-yaml-env-and-blocks.yml", package = "tic"), # nolint
    paste0(tempdir(), "/circle-test-update-yaml-env-and-blocks-updated.yml")
  )

  updated <- readLines(paste0(tempdir(), "/circle-test-update-yaml-env-and-blocks-updated.yml")) # nolint
  solution <- readLines(system.file("testdata/circle-test-update-yaml-env-and-blocks-solution.yml", package = "tic")) # nolint
  expect_equal(updated, solution)
})
ropenscilabs/tic documentation built on Feb. 5, 2024, 5:06 p.m.