File: test-delete.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 (55 lines) | stat: -rw-r--r-- 1,603 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
43
44
45
46
47
48
49
50
51
52
53
54
55
context("delete_by_id")

test_that("delete by ", {
  skip_on_cran()

  if (!collection_exists(conn, "gettingstarted")) {
    collection_create(conn, name = "gettingstarted", numShards = 1)
  }
  ss <- list(list(id = 1, price = 100), list(id = 2, price = 500),
            list(id = 3, price = 100), list(id = 4, price = 500))
  invisible(add(ss, conn, name = "gettingstarted"))

  # single id
  aa <- conn$delete_by_id(ids = 1, "gettingstarted")

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

  # many ids
  aa <- conn$delete_by_id(ids = c(3, 4), "gettingstarted")

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

  res <- conn$get(ids = 3:4, "gettingstarted")
  expect_equal(length(res$response$docs), 0)
})

context("delete_by_query")

test_that("delete by many ids", {
  skip_on_cran()

  ss <- list(list(id = 10, title = "adfadsf"), list(id = 12, title = "though"),
          list(id = 13, title = "cheese"), list(id = 14, title = "animals"))
  invisible(add(ss, conn, name = "gettingstarted"))

  aa <- conn$delete_by_query(query = "title:cheese", "gettingstarted")

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

  res <- conn$search("gettingstarted", params = list(q = "title:cheese"))
  expect_equal(NROW(res), 0)
})

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

  expect_error(delete_by_id(), "argument \"conn\" is missing")
  expect_error(delete_by_query(), "argument \"conn\" is missing")

  expect_error(delete_by_id(5), "conn must be a SolrClient object")
  expect_error(delete_by_query(5), "conn must be a SolrClient object")
})