library(mockery)
library(withr)
test_that("writing and reading returns the secret", {
local_tempfile("tmp")
local_mock("vault:::vault_path" = mock(tmp, cycle = TRUE))
key <- generate_key()
write_secret("Test", "username", "bob_loblaw", key = key)
x <- read_secret("Test", "username", key = key)
expect_s3_class(x, "vault_secret")
expect_equal(vec_data(x), "bob_loblaw")
})
test_that("read_secret and write_secret fail with and ... args", {
local_tempfile("tmp")
local_vault(tmp)
key <- generate_key()
expect_error(read_secret("Test", "username", a = 1, key = key))
expect_error(write_secret("Test", "username", "bob_loblaw", a = 1, key = key))
})
test_that("read_secret returns NULL if secret does not exist", {
local_tempfile("tmp")
local_vault(tmp)
key <- generate_key()
expect_null(read_secret("Test", "username", key = key))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.