tests/testthat/test_util_wget.R

#' ---
#' title: "Test: util_wget"
#' author: "Ivan Jacob Agaloos Pesigan"
#' date: "`r Sys.Date()`"
#' output: rmarkdown::html_vignette
#' vignette: >
#'   %\VignetteIndexEntry{Test: util_wget}
#'   %\VignetteEngine{knitr::rmarkdown}
#'   %\VignetteEncoding{UTF-8}
#' ---
#'
#+ knitr_options, include=FALSE, cache=FALSE
knitr::opts_chunk$set(
  error = TRUE,
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)
#'
#+ setup
library(testthat)
library(jeksterslabRutils)
context("Test util_wget.")
#'
#' ## Set test parameters
#'
#' #+ temp
tmp <- util_make_subdir()
#'
#+ parameters
link <- c(
  "https://raw.githubusercontent.com/jeksterslabds/jeksterslabRutils/master/R/util_bind.R",
  "https://raw.githubusercontent.com/jeksterslabds/jeksterslabRutils/master/R/util_cat_sys.R"
)
files <- c(
  file.path(tmp, "util_bind.R"),
  file.path(tmp, "util_cat_sys.R")
)
Variable <- c(
  "`link`",
  "`files`"
)
Description <- c(
  "Link to files to download.",
  "Files."
)
Value <- c(
  paste(link, collapse = ", "),
  paste(files, collapse = ", ")
)
knitr::kable(
  x = data.frame(
    Variable,
    Description,
    Value
  ),
  row.names = FALSE
)
#'
#' ## Run test
#'
#+ test
util_wget(
  dir = tmp,
  link = link,
  args = "-nc",
  par = FALSE
)
#'
#' ## Results
#'
#+ results
results <- log <- rep(x = NA, times = length(files))
for (i in seq_along(files)) {
  if (file.exists(files[i])) {
    results[i] <- files[i]
    log[i] <- TRUE
  } else {
    results[i] <- NA
    log[i] <- FALSE
  }
}
Parameter <- c(
  paste(link, collapse = ", "),
  paste(files, collapse = ", ")
)
Result <- c(
  paste(link, collapse = ", "),
  paste(results, collapse = ", ")
)
knitr::kable(
  x = data.frame(
    Description,
    Parameter,
    Result
  ),
  row.names = FALSE
)
#'
#+ testthat_01, echo=TRUE
test_that("util_wget works", {
  skip_on_appveyor()
  expect_equivalent(
    all(log),
    TRUE
  )
})
#'
#' ### Clean up temporary files and folders
#'
#+ cleanup
util_clean_dir(
  dir = tmp,
  create_dir = FALSE
)
jeksterslabds/jeksterslabRutils documentation built on Jan. 18, 2021, 11:41 p.m.