File: test-add.R

package info (click to toggle)
r-cran-solrium 1.1.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,132 kB
  • sloc: xml: 374; sh: 13; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
context("add")

test_that("add works with a list and data.frame", {
  skip_on_cran()

  if (!collection_exists(conn, "books")) {
    collection_create(conn, name = "books")
  }

  ss <- list(list(id = 1, price = 100), list(id = 2, price = 500))
  aa <- add(ss, conn, name = "books")

  expect_is(aa, "list")
  expect_named(aa, c("responseHeader"))
  expect_is(conn$get(c(1, 2), "books"), "list")
  expect_named(conn$get(c(1, 2), "books"), "response")


  df <- data.frame(id = c(67, 68), price = c(1000, 500000000))
  aa <- add(df, conn, "books")

  expect_is(aa, "list")
  expect_named(aa, c("responseHeader"))
})

test_that("add works with new interface", {
  skip_on_cran()

  ss <- list(list(id = 1, price = 100), list(id = 2, price = 500))
  aa <- conn$add(ss, name = "books")

  expect_is(aa, "list")
  expect_named(aa, c("responseHeader"))
})

test_that("add fails well", {
  skip_on_cran()

  expect_error(add(), "no applicable method")
  expect_error(add(5), "no applicable method")
  expect_error(add(mtcars, 4), "conn must be a SolrClient object")
})