From eab0c368c7dcff756c055d2c9bf70bd1406087c8 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Tue, 31 Dec 2024 00:38:58 +0000 Subject: [PATCH] add tests for add_github_action; fix #38 --- R/add_github_action.R | 2 +- tests/testthat/_snaps/add_badge/README.Rmd | 23 ------- tests/testthat/test-add_contributing.R | 22 ++++++- tests/testthat/test-add_github_action.R | 70 ++++++++++++++++++++++ 4 files changed, 91 insertions(+), 26 deletions(-) delete mode 100644 tests/testthat/_snaps/add_badge/README.Rmd create mode 100644 tests/testthat/test-add_github_action.R diff --git a/R/add_github_action.R b/R/add_github_action.R index bcb99b0..c9f844e 100644 --- a/R/add_github_action.R +++ b/R/add_github_action.R @@ -34,7 +34,7 @@ add_github_action <- function(gha_name = NULL, overwrite = FALSE) { ) ) - dir.create(".github/workflows") + dir.create(".github/workflows", recursive = TRUE) cli::cli_alert_success( "{.file .github/workflows} directory successfully created." diff --git a/tests/testthat/_snaps/add_badge/README.Rmd b/tests/testthat/_snaps/add_badge/README.Rmd deleted file mode 100644 index 00ebf35..0000000 --- a/tests/testthat/_snaps/add_badge/README.Rmd +++ /dev/null @@ -1,23 +0,0 @@ ---- -output: github_document ---- - - - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "man/figures/README-", - out.width = "100%" -) -``` - -# pakete: Utilities for Package Development - - -[![Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept.](https://www.repostatus.org/badges/latest/concept.svg)](https://www.repostatus.org/#concept) -[![Project Status: Moved to https://panukatan.io – The project has been moved to a new location, and the version at that location should be considered authoritative.](https://www.repostatus.org/badges/latest/moved.svg)](https://www.repostatus.org/#moved) to [https://panukatan.io](https://panukatan.io) -[![CodeFactor](https://www.codefactor.io/repository/github/katilingban/pakete/badge)](https://www.codefactor.io/repository/github/katilingban/pakete) -[![DOI](https://zenodo.org/badge/790010725.svg)](https://zenodo.org/badge/latestdoi/790010725) - diff --git a/tests/testthat/test-add_contributing.R b/tests/testthat/test-add_contributing.R index 9934e31..b778bf9 100644 --- a/tests/testthat/test-add_contributing.R +++ b/tests/testthat/test-add_contributing.R @@ -1,8 +1,6 @@ # Tests for add_contributing functions ----------------------------------------- test_that("add_contributing works as expected", { - expect_type(create_contributing(repo = "katilingban/pakete"), "character") - dir.create(".github") add_contributing(repo = "katilingban/pakete") @@ -15,3 +13,23 @@ test_that("add_contributing works as expected", { file.remove(".github/CONTRIBUTING.md") unlink(".github", recursive = TRUE) }) + + +# test_that("overwrite = TRUE works as expected", { +# dir.create(".github") + +# file.copy( +# from = system.file("templates", "CONTRIBUTING.md", package = "pakete"), +# to = ".github" +# ) + +# add_contributing(repo = "katilingban/pakete", overwrite = TRUE) + +# expect_snapshot_file( +# path = ".github/CONTRIBUTING.md", +# name = "CONTRIBUTING.md" +# ) + +# file.remove(".github/CONTRIBUTING.md") +# unlink(".github", recursive = TRUE) +# }) diff --git a/tests/testthat/test-add_github_action.R b/tests/testthat/test-add_github_action.R new file mode 100644 index 0000000..9dc595c --- /dev/null +++ b/tests/testthat/test-add_github_action.R @@ -0,0 +1,70 @@ +# Tests for add_github_action functions ---------------------------------------- + +test_that("add_github_action works as expected", { + dir.create(".github/workflows", recursive = TRUE) + + expect_error(add_github_action()) + + add_github_action(gha_name = "netlify") + + expect_snapshot_file( + path = ".github/workflows/netlify.yaml", + name = "netlify.yaml" + ) + + file.remove(".github/workflows/netlify.yaml") + unlink(".github", recursive = TRUE) +}) + + +test_that("add_github_action no directory works as expected", { + add_github_action(gha_name = "netlify") + + expect_snapshot_file( + path = ".github/workflows/netlify.yaml", + name = "netlify.yaml" + ) + + file.remove(".github/workflows/netlify.yaml") + unlink(".github", recursive = TRUE) +}) + + +test_that("add_github_action overwrite = TRUE works as expected", { + dir.create(".github/workflows", recursive = TRUE) + + file.copy( + from = system.file("actions", "netlify.yaml", package = "pakete"), + to = ".github/workflows" + ) + + add_github_action(gha_name = "netlify", overwrite = TRUE) + + expect_snapshot_file( + path = ".github/workflows/netlify.yaml", + name = "netlify.yaml" + ) + + file.remove(".github/workflows/netlify.yaml") + unlink(".github", recursive = TRUE) +}) + + +test_that("add_github_action overwrite = FALSE works as expected", { + dir.create(".github/workflows", recursive = TRUE) + + file.copy( + from = system.file("actions", "netlify.yaml", package = "pakete"), + to = ".github/workflows" + ) + + add_github_action(gha_name = "netlify") + + expect_snapshot_file( + path = ".github/workflows/netlify.yaml", + name = "netlify.yaml" + ) + + file.remove(".github/workflows/netlify.yaml") + unlink(".github", recursive = TRUE) +}) \ No newline at end of file