library(testthat)
skip_if_no_auth <- function() {
if (identical(Sys.getenv("client_id"), "") || identical(Sys.getenv("client_secret"), "") || identical(Sys.getenv("tenant"), "")) {
skip("No authentication available")
}
}
context("Authentication functions")
test_that("set_adl_token throws error if tenant is not set",{
skip_if_no_auth()
expect_error(set_adl_token(client_id = Sys.getenv("client_id"), client_secret = Sys.getenv("client_secret")))
})
test_that("set_adl_token throws error if client_id is not set",{
skip_if_no_auth()
expect_error(set_adl_token(tenant = Sys.getenv("tenant"), client_secret = Sys.getenv("client_secret")))
})
test_that("set_adl_token throws error if client_secret is not set",{
skip_if_no_auth()
expect_error(set_adl_token(tenant = Sys.getenv("tenant"), client_id = Sys.getenv("client_id")))
})
test_that("set_adl_token throws error if nothing is not set",{
skip_if_no_auth()
expect_error(set_adl_token())
})
test_that("set_adl_token() properly sets token to environment", {
if(identical(Sys.getenv("client_id"), "")){NULL}else{
set_adl_token(tenant = Sys.getenv("tenant"),
client_id = Sys.getenv("client_id"),
client_secret = Sys.getenv("client_secret"))
}
skip_if_no_auth()
expect_false(Sys.getenv("ADL_TOKEN") == "")
# tokens seem to have 1167 characters
expect_true(nchar(Sys.getenv("ADL_TOKEN")) == 1167L)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.