Commit 72ff7a07 authored by illo's avatar illo
Browse files

test package with rhub

parent fbf36076
Pipeline #238247618 passed with stage
in 12 seconds
......@@ -6,6 +6,7 @@ Authors@R:
family = "Haag",
role = c("aut", "cre"),
email = "oliver_haag@e.mail.de")
Maintainer: 'Oliver Haag <oliver_haag@e.mail.de>'
URL: https://gitlab.com/rpkgs/mongopipe
Description: Translate R code into MongoDB aggregation pipelines.
License: MIT + file LICENSE
......
......@@ -5,7 +5,7 @@ devtools::check()
pkgdown::build_site()
# check for cran
# rhub::check_for_cran() not working because of mongodb
rhub::check_for_cran()
# Check for win-builder
devtools::check_win_devel()
......
library(testthat)
library(mongopipe)
library(mongolite)
test_check("mongopipe")
library(mongolite)
library(nycflights13)
m_flights <- mongo("test_flights", verbose = FALSE)
m_airports <- mongo("test_airports", verbose = FALSE)
if(!m_flights$count())
m_flights$insert(flights)
if(!m_airports$count())
m_airports$insert(airports)
test_that("check_query", {
expect_error(check_query(list(1)),
"all elements in query should have names!")
expect_error(check_query(list(x=list(1,2,3))),
"all elements in query should have names!")
expect_error(check_query(list(x=2)), NA)
expect_error(check_query(list(x=2:5)), NA)
})
test_that("aggregate", {
test_that("add_stage", {
pipeline <- add_stage("$match", list(flight=1545))
expect_s3_class(pipeline, "mongopipe")
df_pipe <- m_flights$aggregate(pipeline)
expect_equal(nrow(df_pipe), 149)
expect_equal(as.character(pipeline), "[{\"$match\":{\"flight\":1545}}]")
})
test_that("match", {
pipe_match <- match(mongopipe(), dest="ABQ")
expect_equal(capture.output(pipe_match), c("[",
" {",
" \"$match\": {",
" \"dest\": \"ABQ\"",
" }",
" }",
"]"))
df_match <- m_flights$aggregate(pipe_match)
expect_equal(nrow(df_match), 254)
expect_snapshot_output(cat(pipe_match))
})
test_that("pipe", {
result <- mongopipe() %>%
pipe <- mongopipe() %>%
match(faa="ABQ") %>%
lookup(from = "test_flights",
local_field = "faa",
foreign_field = "dest") %>%
unwind(field = "test_flights") %>%
m_airports$aggregate()
unwind(field = "test_flights")
expect_equal(nrow(result), 254)
expect_snapshot_output(cat(pipe))
result2 <- mongopipe() %>%
pipe2 <- mongopipe() %>%
match(tzone="America/New_York") %>%
lookup(from = "test_flights",
local_field = "faa",
......@@ -70,10 +28,9 @@ test_that("pipe", {
field(min_distance = list("$min"="$test_flights.distance")) %>%
match(min_distance=list("$ne"=NA)) %>%
project("min_distance"=1, "faa"=1) %>%
limit(3) %>%
m_airports$aggregate()
limit(3)
expect_true(!all(is.na(result2$min_distance)))
expect_snapshot_output(cat(pipe2))
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment