Skip to content

Commit

Permalink
Merge pull request #164 from nuest/master
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
nuest authored Aug 20, 2019
2 parents 5d75fe0 + f980627 commit e8a9924
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion R/package-installation-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ add_install_instructions <- function(dockerfile,
pkgs <- rbind(cran_packages[!skipable,], pkgs[pkgs$source != "CRAN",])
}

# 0. Installing github packages requires the package 'remotes'
# 0. Installing github packages requires the package 'remotes' (and devtools for R < 3.4, which is not suppoted), see https://github.com/eddelbuettel/littler/blob/master/inst/examples/installGithub.r#L12
if (nrow(pkgs[pkgs$source == "github",]) > 0 && !"remotes" %in% pkgs$name) {
pkgs <- rbind(pkgs, remotes = data.frame(name = "remotes", version = "1.1.1", source = "CRAN"))
futile.logger::flog.debug("Added package 'remotes' to package list to be able to install from GitHub")
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/github/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Package: containerittest
Version: 1.2.3
Title: Simple Features for R
Authors@R: c(person(given = "o2",
family = "r",
role = c("aut", "cre"),
email = "o2r-team@uni-muenster.de"))
Description: Test description
License: file LICENSE
URL: https://test.com
Depends: methods, R (>= 3.5.0)
Imports: graphics
Encoding: UTF-8
Collate: 'code.R'
NeedsCompilation: yes
Author: o2 r [aut, cre]
Maintainer: o2 r <o2r-team@uni-muenster.de>
Remotes: github::some-org/the_package
8 changes: 4 additions & 4 deletions tests/testthat/package_description/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: containerittest
Package: here
Version: 1.2.3
Title: Simple Features for R
Title: Fake DESCRIPTION file for containerit testing
Authors@R: c(person(given = "o2",
family = "r",
role = c("aut", "cre"),
email = "o2r-team@uni-muenster.de"))
Description: Test description
License: file LICENSE
URL: https://test.com
Depends: methods, R (>= 3.3.0)
Depends: methods, R (>= 3.4.0)
Imports: graphics, grDevices, grid, Rcpp (>= 0.12.18), units (>= 0.6-0), utils
Suggests: covr, dplyr (>= 0.8-0), ggplot2, knitr, lwgeom (>= 0.1-5), maps
Encoding: UTF-8
Expand All @@ -17,5 +17,5 @@ Collate: 'code.R'
NeedsCompilation: yes
Author: o2 r [aut, cre]
Maintainer: o2 r <o2r-team@uni-muenster.de>
Remotes: github::r-hub/sysreqs,gitlab::test/pkg
Remotes: github::r-hub/sysreqs,gitlab::test/pkg,github::viking/r-yaml@v2.1.17
biocViews: Sequencing, RNASeq
6 changes: 3 additions & 3 deletions tests/testthat/package_description/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM rocker/r-ver:3.3.0
FROM rocker/r-ver:3.4.0
LABEL maintainer="o2r"
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
&& apt-get install -y git-core \
libudunits2-dev
RUN ["install2.r", "containerittest", "graphics", "grDevices", "grid", "Rcpp", "remotes", "units", "utils"]
RUN ["installGithub.r", "r-hub/sysreqs@master"]
RUN ["install2.r", "graphics", "grDevices", "grid", "here", "Rcpp", "remotes", "units", "utils"]
RUN ["installGithub.r", "r-hub/sysreqs@master", "viking/r-yaml@v2.1.17"]
WORKDIR /payload/
CMD ["R"]
6 changes: 3 additions & 3 deletions tests/testthat/package_description/Dockerfile.versioned
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM rocker/r-ver:3.3.0
FROM rocker/r-ver:3.4.0
LABEL maintainer="o2r"
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
&& apt-get install -y git-core \
libudunits2-dev
RUN ["install2.r", "versions"]
RUN ["install2.r", "graphics", "grDevices", "grid", "Rcpp", "units", "utils"]
RUN ["Rscript", "-e", "versions::install.versions('containerittest', '1.2.3')", "-e", "versions::install.versions('remotes', '1.1.1')"]
RUN ["installGithub.r", "r-hub/sysreqs@master"]
RUN ["Rscript", "-e", "versions::install.versions('here', '1.2.3')", "-e", "versions::install.versions('remotes', '1.1.1')"]
RUN ["installGithub.r", "r-hub/sysreqs@master", "viking/r-yaml@v2.1.17"]
WORKDIR /payload/
CMD ["R"]
12 changes: 12 additions & 0 deletions tests/testthat/test_find_systemrequirements.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

context("Find system requrirements")

skip_if_crandeps_offline <- function() {
skip_if_not_installed("httr")
if (httr::status_code(httr::HEAD(url = "crandeps.r-pkg.org")) != 200)
skip("crandeps not available")
}

test_that("System requirements for sp can be detected OFFLINE and soft", {
skip_if_crandeps_offline()

output <- capture_output(
deps <- containerit:::.find_system_dependencies("sp",
platform = containerit:::.debian_platform,
Expand All @@ -15,6 +23,8 @@ test_that("System requirements for sp can be detected OFFLINE and soft", {
})

test_that("System requirements for sp can be detected OFFLINE and unsoft", {
skip_if_crandeps_offline()

output <- capture_output(
deps <- containerit:::.find_system_dependencies("sp",
platform = containerit:::.debian_platform,
Expand All @@ -25,6 +35,8 @@ test_that("System requirements for sp can be detected OFFLINE and unsoft", {
})

test_that("System requirements for rgdal can be detected OFFLINE", {
skip_if_crandeps_offline()

output <- capture_output(
deps <- containerit:::.find_system_dependencies("rgdal",
platform = containerit:::.debian_platform,
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test_install_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ test_that("GitHub references can be retrieved for package sysreqs (test fails if
ref <- getGitHubRef("sysreqs", c(sessionInfo()$otherPkgs, sessionInfo()$loadedOnly))
expect_match(ref, "r-hub/sysreqs@([a-f0-9]{7})")
})

test_that("the package remotes is installed if not already in the list of packages", {
output <- capture_output(
the_dockerfile <- dockerfile(from = "github/DESCRIPTION",
maintainer = "o2r")
)
expect_true(any(stringr::str_detect(toString(the_dockerfile),
"^RUN \\[\"install2.r\", \"containerittest\", \"graphics\", \"remotes\"\\]$")))
expect_true(any(stringr::str_detect(toString(the_dockerfile),
"^RUN \\[\"installGithub.r\", \"some-org/the_package@master\"\\]$")))
})

test_that("the package remotes is installed in the correct version if not already in the list of packages", {
output <- capture_output(
the_dockerfile <- dockerfile(from = "github/DESCRIPTION",
maintainer = "o2r",
versioned_packages = TRUE)
)
expect_true(any(stringr::str_detect(toString(the_dockerfile),
"versions::install.versions\\('remotes', '1.1.1'\\)")))
})
27 changes: 26 additions & 1 deletion tests/testthat/test_package_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ context("Packaging a DESCRIPTION file")
test_that("version tag can be extracted from DESCRIPTION object", {
description <- desc::desc(file = "package_description/DESCRIPTION")
version <- getRVersionTag(description)
expect_equal(version, "3.3.0")
expect_equal(version, "3.4.0")
})

test_that("a DESCRIPTION file can be packaged", {
Expand Down Expand Up @@ -60,3 +60,28 @@ test_that("the version of the packaged DESCRIPTION package can be installed for
expected_file <- readLines("package_description/Dockerfile.sf.versioned")
expect_equal(capture.output(print(the_dockerfile)), expected_file)
})

test_that("the Dockerfile (unversioned) can be built and run", {
skip_if_not(stevedore::docker_available())

output <- capture_output(the_dockerfile <- dockerfile(from = "package_description/DESCRIPTION",
maintainer = "o2r"))

the_dockerfile_dir <- tempdir()
write(x = the_dockerfile, file = file.path(the_dockerfile_dir, "Dockerfile"))

output <- capture_output({
client <- stevedore::docker_client()
build <- client$image$build(context = the_dockerfile_dir,
dockerfile = "Dockerfile",
tag = "containerit_test_versioned_packages")
run <- client$container$run(image = build$id(), rm = TRUE, cmd = c('Rscript',
'-e', 'library(\"here\");',
'-e', 'library(\"yaml\");',
'-e', 'sessionInfo();'))
})

expect_match(toString(run$logs), "R version 3.4.0")
expect_match(toString(run$logs), "here_")
expect_match(toString(run$logs), "yaml_2.1.17")
})
4 changes: 2 additions & 2 deletions tests/testthat/test_save_workspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
context("Save workspace and R objects (save_image - argument)")

test_that("Session objects with default file name can be containerized", {
rm(list = ls(envir = environment()), envir = environment()) # start clean
expect_false(file.exists(".RData"), "RData file already exists in testthat folder. Remove manually and restart test.")

test_text <- "test"
Expand Down Expand Up @@ -37,7 +36,6 @@ test_that("Session objects with default file name can be containerized", {
})

test_that("Selected session objects with configured file name can be containerized", {
rm(list = ls(envir = environment()), envir = environment()) # start clean
expect_false(file.exists("test_file.RData"), "RData file already exists in testthat folder. Remove manually and restart test.")

test_text <- "test"
Expand Down Expand Up @@ -69,6 +67,8 @@ test_that("Selected session objects with configured file name can be containeriz
})

test_that("Program ignores unsupported input for save_image", {
expect_false(file.exists(".RData"), "RData file already exists in testthat folder. Remove manually and restart test.")

output <- capture_output(
expect_s4_class(dockerfile(from = sessionInfo(), save_image = data.frame()), "Dockerfile")
)
Expand Down

0 comments on commit e8a9924

Please sign in to comment.