File: test_hash_multihash.R

package info (click to toggle)
r-cran-openssl 1.4.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,288 kB
  • sloc: ansic: 3,021; sh: 97; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download
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
context("Multihash")

test_that("Multihash for connections or raw vectors", {
  desc <- system.file('DESCRIPTION')
  buf <- readBin(desc, raw(), 1e5)
  algos <- c("md5", "sha1", "sha256", "sha512")
  out1 <- multihash(buf, algos = algos)
  out2 <- multihash(file(desc), algos = algos)
  expect_identical(out1, out2)
  expect_named(out1, algos)
  expect_equal(out1$md5, md5(file(desc)))
  expect_equal(out1$sha1, sha1(file(desc)))
  expect_equal(out1$sha256, sha256(file(desc)))
  expect_equal(out1$sha512, sha512(file(desc)))
})

test_that("Multihash for text vectors", {
  algos <- c("md5", "sha1", "sha256", "sha512")
  out0 <- multihash(character(), algos = algos)
  expect_is(out0, 'data.frame')
  expect_named(out0, algos)
  expect_equal(nrow(out0), 0)

  out1 <- multihash("foo", algos = algos)
  expect_is(out1, 'data.frame')
  expect_named(out1, algos)
  expect_equal(nrow(out1), 1)

  out2 <- multihash(c("foo", "bar"), algos = algos)
  expect_is(out2, 'data.frame')
  expect_named(out2, algos)
  expect_equal(nrow(out2), 2)

  expect_equal(out2[1,], out1)

})