Skip to content

Commit

Permalink
skip lockfile validation tests on CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Sep 23, 2024
1 parent 99339c7 commit 8a6c882
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/testthat/test-lockfile-validate.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

test_that("a known-good lockfile passes validation", {


skip_on_cran()
skip_if_not_installed("jsonvalidate")

lockfile <- '
{
"R": {
Expand Down Expand Up @@ -53,11 +55,13 @@ test_that("a known-good lockfile passes validation", {
'
expect_no_error(lockfile_validate(lockfile = lockfile))
expect_true(lockfile_validate(lockfile = lockfile))

})


test_that("a known-good lockfile with extra fields passes validation", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

# Lockfile adds a R$Nickname field not present in the schema
Expand Down Expand Up @@ -113,10 +117,12 @@ test_that("a known-good lockfile with extra fields passes validation", {
'
expect_no_error(lockfile_validate(lockfile = lockfile))
expect_true(lockfile_validate(lockfile = lockfile))

})

test_that("a custom schema file can be used for successful validation", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

# Custom schema adds a required R$Nickname field present in the lockfile
Expand Down Expand Up @@ -166,10 +172,12 @@ test_that("a custom schema file can be used for successful validation", {
'
expect_no_error(lockfile_validate(lockfile = lockfile, schema = schema))
expect_true(lockfile_validate(lockfile = lockfile, schema = schema))

})

test_that("a custom schema file can be used for failed validation", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

# Custom schema adds a required R$Nickname field not present in the lockfile
Expand Down Expand Up @@ -218,10 +226,12 @@ test_that("a custom schema file can be used for failed validation", {
'

expect_false(lockfile_validate(lockfile = lockfile, schema = schema))

})

test_that("an incorrect Packages$Hash field fails validation", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

lockfile <- '
Expand All @@ -248,10 +258,12 @@ test_that("an incorrect Packages$Hash field fails validation", {
'

expect_false(lockfile_validate(lockfile = lockfile))

})

test_that("invalid JSON fails validation", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

# Packages uses [] which is not valid JSON
Expand All @@ -278,10 +290,12 @@ test_that("invalid JSON fails validation", {
}
'
expect_error(lockfile_validate(lockfile = lockfile, error = TRUE))

})

test_that("strict mode catches unknown keyword in provided schema", {

skip_on_cran()
skip_if_not_installed("jsonvalidate")

# Custom schema provides "Version" with "type": "UNKNOWN"
Expand Down Expand Up @@ -324,5 +338,7 @@ test_that("strict mode catches unknown keyword in provided schema", {
}
}
'

expect_error(lockfile_validate(lockfile = lockfile, strict = TRUE))

})

0 comments on commit 8a6c882

Please sign in to comment.