Skip to content

Commit

Permalink
Increased Code Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiyush04 committed Jun 3, 2021
1 parent 6218021 commit 2380373
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 65 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Imports:
httr,
methods,
utils,
tools,
httptest
tools
Suggests:
covr,
knitr,
reprex,
rmarkdown,
testthat (>= 3.0.0),
httptest,
vcr
VignetteBuilder:
knitr
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export(get_history)
export(post_bug)
export(post_comment)
export(set_key)
import(httptest)
importFrom(cli,cat_rule)
importFrom(cli,cli_alert)
importFrom(cli,cli_alert_danger)
Expand Down
1 change: 0 additions & 1 deletion R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ missing_key <- function(key) {
#' @importFrom cli cli_ul
#' @importFrom utils browseURL
#' @export
#' @import httptest
create_bugzilla_key <- function(host) {
host <- missing_host(host)
url <- paste0(host, "userprefs.cgi?tab=apikey")
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/set_key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

104 changes: 104 additions & 0 deletions tests/testthat/_snaps/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# cli_alert_warning works [plain]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [ansi]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [unicode]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [fancy]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_danger [plain]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Message <cliMessage>
x Not authenticated on this site.
Code
cli::cli_alert_success("Authenticated on this site!")
Message <cliMessage>
v Authenticated on this site!

# cli_alert_danger [ansi]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Message <cliMessage>
x Not authenticated on this site.
Code
cli::cli_alert_success("Authenticated on this site!")
Message <cliMessage>
v Authenticated on this site!

# cli_alert_danger [unicode]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Message <cliMessage>
✖ Not authenticated on this site.
Code
cli::cli_alert_success("Authenticated on this site!")
Message <cliMessage>
✔ Authenticated on this site!

# cli_alert_danger [fancy]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Message <cliMessage>
✖ Not authenticated on this site.
Code
cli::cli_alert_success("Authenticated on this site!")
Message <cliMessage>
✔ Authenticated on this site!

# cli_alert_dangers [plain]

Code
cli::cli_alert_danger("Key not valid or not set.")
Message <cliMessage>
x Key not valid or not set.

# cli_alert_dangers [ansi]

Code
cli::cli_alert_danger("Key not valid or not set.")
Message <cliMessage>
x Key not valid or not set.

# cli_alert_dangers [unicode]

Code
cli::cli_alert_danger("Key not valid or not set.")
Message <cliMessage>
✖ Key not valid or not set.

# cli_alert_dangers [fancy]

Code
cli::cli_alert_danger("Key not valid or not set.")
Message <cliMessage>
✖ Key not valid or not set.

64 changes: 3 additions & 61 deletions tests/testthat/setup-bugRzilla.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
library("vcr") # *Required* as vcr is set up on loading
library("httptest")
library("httptest") # *Required* as hhtptest is set up on loading

vcr_dir <- vcr::vcr_test_path("fixtures")
if (!nzchar(Sys.getenv("R_BUGZILLA"))) {
Expand All @@ -13,68 +13,10 @@ if (!nzchar(Sys.getenv("R_BUGZILLA"))) {

use_key()

test_that("create_bugzilla_key works", {
vcr::use_cassette("create_bugzilla_key", {
host <- "https://bugs.r-project.org/bugzilla/"
cbk <- create_bugzilla_key(host)
})
expect_equal(a <- paste0(host, "userprefs.cgi?tab=apikey"), url)
cli::test_that_cli("cli_alert_warning works", {
expect_snapshot({
cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.")
})
})
})


test_that("check_authentication works", {
vcr::use_cassette("check_authentication", {
ca <- check_authentication(host)
})
expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/")
cli::test_that_cli("cli_alert_danger",{
expect_snapshot({
cli::cli_alert_danger("Not authenticated on this site.")
cli::cli_alert_success("Authenticated on this site!")
})
})
})

test_that("check_api_version works", {
vcr::use_cassette("check_api_version", {
cav <- check_api_version(host)
})
expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/")
})


test_that("check_last_audit works", {
vcr::use_cassette("check_last_audit", {
product <- "R"
cla <- check_last_audit(product, host)
})
expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/")
httptest::expect_GET(paste0(host, "rest/last_audit_time"), "https://bugs.r-project.org/bugzilla/rest/last_audit_time")
expect_equal(missing_product(product), "R")
})


invisible(vcr::vcr_configure(
dir = vcr_dir,
filter_request_headers = list(
"Authorization" = "My bearer token is safe",
"X-BUGZILLA-API-KEY" = "Removing this header too just in case")
"Authorization" = "My bearer token is safe",
"X-BUGZILLA-API-KEY" = "Removing this header too just in case")
))
vcr::check_cassette_names()


test_that("valid_key works", {
use_cassette("valid_key", {
vk <- valid_key("R_BUGZILLA")
})
cli::test_that_cli("cli_alert_danger", {
expect_snapshot({
cli::cli_alert_danger("Key not valid or not set.")
})
})
})
59 changes: 59 additions & 0 deletions tests/testthat/test-api.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
test_that("create_bugzilla_key works", {
vcr::use_cassette("create_bugzilla_key", {
cbk <- create_bugzilla_key(missing_host())
url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey"
})
expect_equal(paste0(missing_host(), "userprefs.cgi?tab=apikey"), url)
expect_condition()
cli::test_that_cli("cli_alert_warning works", {
expect_snapshot({
cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.")
})
})
})


test_that("check_authentication works", {
vcr::use_cassette("check_authentication", {
ca <- check_authentication(missing_host())
})
expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/")
cli::test_that_cli("cli_alert_danger",{
expect_snapshot({
cli::cli_alert_danger("Not authenticated on this site.")
cli::cli_alert_success("Authenticated on this site!")
})
})
})


test_that("check_api_version works", {
vcr::use_cassette("check_api_version", {
cav <- check_api_version(missing_host())
})
expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/")
})


test_that("check_last_audit works", {
vcr::use_cassette("check_last_audit", {
cla <- check_last_audit(missing_product(), missing_host())
})
expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/")
expect_equal(missing_product(), "R")
expect_s3_class(GET(paste0(missing_host(), "rest/last_audit_time")), "response")
})


test_that("valid_key works", {
use_cassette("valid_key", {
vk <- valid_key(use_key())
})
cli::test_that_cli("cli_alert_dangers", {
expect_snapshot({
cli::cli_alert_danger("Key not valid or not set.")
})
})
})

snapshot_accept('R/api.R')

0 comments on commit 2380373

Please sign in to comment.