Skip to content

Commit

Permalink
Merge pull request #47 from katilingban:dev
Browse files Browse the repository at this point in the history
add tests for add_github_action; fix #38
  • Loading branch information
ernestguevarra authored Dec 31, 2024
2 parents d120c46 + eab0c36 commit b817976
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 26 deletions.
2 changes: 1 addition & 1 deletion R/add_github_action.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
23 changes: 0 additions & 23 deletions tests/testthat/_snaps/add_badge/README.Rmd

This file was deleted.

22 changes: 20 additions & 2 deletions tests/testthat/test-add_contributing.R
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
# })
70 changes: 70 additions & 0 deletions tests/testthat/test-add_github_action.R
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit b817976

Please sign in to comment.