Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: replace httptest with httptest2 as gh now uses httr2 instead of httr #646

Merged
merged 3 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Suggests:
fs,
gert (>= 1.4.0),
gh,
httptest,
httptest2,
jsonlite,
knitr,
mockery,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"number": 332,
"title": "feat: Improve parsing of conventional commit messages"
}
1 change: 0 additions & 1 deletion tests/testthat/helper-httptest.R

This file was deleted.

5 changes: 5 additions & 0 deletions tests/testthat/helper-httptest2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library("httptest2")

with_mock_dir <- function(name, ...) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided it was cleaner to have fixtures in their own folder.

httptest2::with_mock_dir(file.path("../fixtures", name), ...)
}
22 changes: 11 additions & 11 deletions tests/testthat/test-parse-news-items.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ test_that("Can parse Co-authored-by", {

test_that("Can parse PR merge commits", {
withr::local_envvar("FLEDGE_TEST_GITHUB_SLUG" = "cynkra/fledge")
httptest::with_mock_dir("pr", {
with_mock_dir("pr", {
withr::local_envvar("YES_INTERNET_TEST_FLEDGE" = "bla")
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
expect_snapshot_tibble(extract_newsworthy_items("Merge pull request #332 from cynkra/conventional-parsing"))
})
})

test_that("Can parse PR merge commits - external contributor", {
withr::local_envvar("FLEDGE_TEST_GITHUB_SLUG" = "cynkra/fledge")
httptest::with_mock_dir("pr0", {
with_mock_dir("pr0", {
withr::local_envvar("YES_INTERNET_TEST_FLEDGE" = "bla")
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
expect_snapshot(suppressMessages(
# https://github.com/nealrichardson/httptest/issues/75
extract_newsworthy_items("Merge pull request #18 from someone/conventional-parsing")
Expand All @@ -63,18 +63,18 @@ test_that("Can parse PR merge commits - external contributor", {

test_that("Can parse PR merge commits - linked issues", {
withr::local_envvar("FLEDGE_TEST_GITHUB_SLUG" = "cynkra/fledge")
httptest::with_mock_dir("pr2", {
with_mock_dir("pr2", {
withr::local_envvar("YES_INTERNET_TEST_FLEDGE" = "bla")
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
expect_snapshot_tibble(extract_newsworthy_items("Merge pull request #328 from cynkra/blop"))
})
})


test_that("Can parse PR merge commits - internet error", {
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
withr::local_envvar("FLEDGE_TEST_GITHUB_SLUG" = "cynkra/fledge")
withr::local_envvar("NO_INTERNET_TEST_FLEDGE" = "blop")
expect_snapshot(extract_newsworthy_items("Merge pull request #332 from cynkra/conventional-parsing"))
Expand All @@ -83,19 +83,19 @@ test_that("Can parse PR merge commits - internet error", {
test_that("Can parse PR merge commits - PAT absence", {
skip_if_offline()
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
withr::local_envvar("FLEDGE_TEST_NO_PAT" = "blop")
expect_snapshot_error(extract_newsworthy_items("Merge pull request #332 from cynkra/conventional-parsing"))
})

test_that("Can parse PR merge commits - other error", {
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
withr::local_envvar("FLEDGE_TEST_GITHUB_SLUG" = "cynkra/fledge")
bla <- function(...) stop("bla")
mockery::stub(harvest_pr_data, "gh::gh", bla)
httptest::with_mock_dir("pr", {
with_mock_dir("pr", {
withr::local_envvar("FLEDGE_TEST_SCOPES" = "bla")
withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
#withr::local_envvar("GITHUB_PAT" = "ghp_111111111111111111111111111111111111111")
expect_snapshot_tibble(harvest_pr_data("Merge pull request #332 from cynkra/conventional-parsing"))
})
})