This commit is contained in:
Hong Ooi 2020-10-22 16:05:18 +11:00
Родитель 2b28939c3d
Коммит 166e651ee9
8 изменённых файлов: 121 добавлений и 4 удалений

Просмотреть файл

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
S3method(azure_table,table_endpoint)
S3method(create_azure_table,azure_table)
S3method(create_azure_table,table_endpoint)
S3method(delete_azure_table,azure_table)
S3method(delete_azure_table,table_endpoint)

Просмотреть файл

@ -2,6 +2,18 @@
#' @import AzureStor
NULL
utils::globalVariables(c("self", "private"))
.onLoad <- function(libname, pkgname)
{
AzureStor::az_storage$set("public", "get_table_endpoint", overwrite=TRUE,
function(key=self$list_keys()[1], sas=NULL, token=NULL)
{
table_endpoint(self$properties$primaryEndpoints$table, key=key, sas=sas, token=token)
})
}
# assorted imports of friend functions
sign_sha256 <- get("sign_sha256", getNamespace("AzureStor"))

Просмотреть файл

@ -1,6 +1,6 @@
#' Operations with azure tables
#'
#' @param endpoint An object of class `table_endpoint`.
#' @param endpoint An object of class `table_endpoint` or, for `create_azure_table.azure_table`, an object of class `azure_table`.
#' @param name The name of a table in a storage account.
#' @param confirm For deleting a table, whether to ask for confirmation.
#' @param ... Other arguments passed to lower-level functions.
@ -17,9 +17,11 @@
#' endp <- table_endpoint("https://mystorageacct.table.core.windows.net", key="mykey")
#'
#' create_azure_table(endp, "mytable")
#' tab <- azure_table(endp, "mytable")
#' tab <- azure_table(endp, "mytable2")
#' create_azure_table(tab)
#' list_azure_tables(endp)
#' delete_azure_table(tab)
#' delete_azure_table(endp, "mytable")
#'
#' }
#' @export
@ -80,6 +82,13 @@ create_azure_table.table_endpoint <- function(endpoint, name, ...)
azure_table(endpoint, res$TableName)
}
#' @rdname azure_table
#' @export
create_azure_table.azure_table <- function(endpoint, ...)
{
create_azure_table(endpoint$endpoint, endpoint$name)
}
#' @rdname azure_table
#' @export

Просмотреть файл

@ -7,6 +7,7 @@
\alias{list_azure_tables.table_endpoint}
\alias{create_azure_table}
\alias{create_azure_table.table_endpoint}
\alias{create_azure_table.azure_table}
\alias{delete_azure_table}
\alias{delete_azure_table.table_endpoint}
\alias{delete_azure_table.azure_table}
@ -24,6 +25,8 @@ create_azure_table(endpoint, ...)
\method{create_azure_table}{table_endpoint}(endpoint, name, ...)
\method{create_azure_table}{azure_table}(endpoint, ...)
delete_azure_table(endpoint, ...)
\method{delete_azure_table}{table_endpoint}(endpoint, name, confirm = TRUE, ...)
@ -31,7 +34,7 @@ delete_azure_table(endpoint, ...)
\method{delete_azure_table}{azure_table}(endpoint, ...)
}
\arguments{
\item{endpoint}{An object of class \code{table_endpoint}.}
\item{endpoint}{An object of class \code{table_endpoint} or, for \code{create_azure_table.azure_table}, an object of class \code{azure_table}.}
\item{...}{Other arguments passed to lower-level functions.}
@ -54,9 +57,11 @@ These methods are for accessing and managing tables within a storage account.
endp <- table_endpoint("https://mystorageacct.table.core.windows.net", key="mykey")
create_azure_table(endp, "mytable")
tab <- azure_table(endp, "mytable")
tab <- azure_table(endp, "mytable2")
create_azure_table(tab)
list_azure_tables(endp)
delete_azure_table(tab)
delete_azure_table(endp, "mytable")
}
}

4
tests/testthat.R Normal file
Просмотреть файл

@ -0,0 +1,4 @@
library(testthat)
library(AzureTableStor)
test_check("AzureTableStor")

4
tests/testthat/setup.R Normal file
Просмотреть файл

@ -0,0 +1,4 @@
make_name <- function(n=20)
{
paste0(sample(letters, n, TRUE), collapse="")
}

Просмотреть файл

@ -0,0 +1,49 @@
context("Table endpoint")
tenant <- Sys.getenv("AZ_TEST_TENANT_ID")
app <- Sys.getenv("AZ_TEST_APP_ID")
password <- Sys.getenv("AZ_TEST_PASSWORD")
subscription <- Sys.getenv("AZ_TEST_SUBSCRIPTION")
if(tenant == "" || app == "" || password == "" || subscription == "")
skip("Authentication tests skipped: ARM credentials not set")
rgname <- Sys.getenv("AZ_TEST_STORAGE_RG")
storname <- Sys.getenv("AZ_TEST_STORAGE_HNS")
if(rgname == "" || storname == "")
skip("Table client tests skipped: resource names not set")
sub <- AzureRMR::az_rm$new(tenant=tenant, app=app, password=password)$get_subscription(subscription)
stor <- sub$get_resource_group(rgname)$get_storage_account(storname)
options(azure_storage_progress_bar=FALSE)
endp <- stor$get_table_endpoint()
test_that("Table endpoint works",
{
endp2 <- table_endpoint(stor$properties$primaryEndpoints$table, key=stor$list_keys()[1])
expect_is(endp, "table_endpoint")
expect_identical(endp, endp2)
expect_true(is_empty(list_azure_tables(endp)))
# ways of creating a container
name1 <- make_name()
tab <- azure_table(endp, name1)
create_azure_table(tab)
create_azure_table(endp, make_name())
lst <- list_azure_tables(endp)
expect_true(is.list(lst) && inherits(lst[[1]], "azure_table") && length(lst) == 2)
expect_identical(tab$name, lst[[name1]]$name)
expect_silent(delete_azure_table(tab, confirm=FALSE))
})
teardown({
lst <- list_azure_tables(endp)
lapply(lst, delete_azure_table, confirm=FALSE)
})

Просмотреть файл

@ -0,0 +1,33 @@
context("Cosmos DB table endpoint")
cosmosdb <- Sys.getenv("AZ_TEST_COSMOSDB_TABLE")
key <- Sys.getenv("AZ_TEST_COSMOSDB_TABLE_KEY")
if(cosmosdb == "" || key == "")
skip("Cosmos DB table client tests skipped: resource names not set")
endp <- table_endpoint(sprintf("https://%s.table.cosmos.azure.com:443", cosmosdb), key=key)
test_that("Table endpoint works",
{
expect_true(is_empty(list_azure_tables(endp)))
# ways of creating a container
name1 <- make_name()
tab <- azure_table(endp, name1)
create_azure_table(tab)
create_azure_table(endp, make_name())
lst <- list_azure_tables(endp)
expect_true(is.list(lst) && inherits(lst[[1]], "azure_table") && length(lst) == 2)
expect_identical(tab$name, lst[[name1]]$name)
expect_silent(delete_azure_table(tab, confirm=FALSE))
})
teardown({
lst <- list_azure_tables(endp)
lapply(lst, delete_azure_table, confirm=FALSE)
})