* fix error message

* refactor check

* fix failing test

* add test
This commit is contained in:
Hong Ooi 2020-07-22 23:33:23 +10:00 коммит произвёл GitHub
Родитель 4366afe6e1
Коммит 747031c543
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 53 добавлений и 11 удалений

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

@ -1,6 +1,6 @@
Package: AzureRMR
Title: Interface to 'Azure Resource Manager'
Version: 2.3.4
Version: 2.3.4.9000
Authors@R: c(
person("Hong", "Ooi", , "hongooi@microsoft.com", role = c("aut", "cre")),
person("Microsoft", role="cph")

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

@ -1,3 +1,7 @@
# AzureRMR 2.3.4.9000
- Fix a bug in printing the error message when a template deployment fails.
# AzureRMR 2.3.4
- Add filtering arguments (`filter`, `expand` and `top`) for the `list_resource_groups`, `list_templates` and `list_resources` methods, to trim the results. See the Azure docs for more details.

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

@ -257,13 +257,11 @@ private=list(
message("\nDeployment successful")
else
{
err_details <- parms$properties$error$details
if(is.list(err_details))
{
msgs <- lapply(err_details, function(x) error_message(jsonlite::fromJSON(x$message)))
stop("\nUnable to deploy template. Message:\n", do.call(paste0, msgs))
}
else stop("\nUnable to deploy template", call.=FALSE)
err_details <- lapply(parms$properties$error$details, `[[`, "message")
msg <- if(is.list(err_details) && !is_empty(err_details))
paste0("\nUnable to deploy template. Message(s):\n", do.call(paste, c(err_details, sep="\n")))
else "\nUnable to deploy template"
stop(msg, call.=FALSE)
}
}
parms

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

@ -0,0 +1,30 @@
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "azurermrtestbad1",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"location": "westus",
"sku": {
"name": "bad_error"
},
"kind": "Storage"
},
{
"name": "azurermrtestbad2",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"location": "westus",
"sku": {
"name": "bad_error"
},
"kind": "Storage"
}
],
"outputs": {}
}

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

@ -26,7 +26,8 @@ test_that("Resource methods work",
res <- rg$create_resource(type=restype, name=resname,
kind="Storage",
sku=list(name="Standard_LRS", tier="Standard"))
sku=list(name="Standard_LRS", tier="Standard"),
wait=TRUE)
expect_true(rg$resource_exists(type=restype, name=resname))
expect_is(res, "az_resource")
@ -87,7 +88,8 @@ test_that("Extended resource fields works",
osType=""
),
sku=list(name="Standard_LRS"),
zones=list(1)
zones=list(1),
wait=TRUE
)
expect_true(rg$resource_exists(type=restype, name=resname))
@ -101,8 +103,9 @@ test_that("Extended resource fields works",
test_that("List filters work",
{
Sys.sleep(10) # let Azure catch up
reslst0 <- rg$list_resources()
expect_true(length(reslst0) > 1)
expect_identical(length(reslst0), 3L)
reslst <- rg$list_resources(top=1)
expect_true(is.list(reslst) && length(reslst) == 1)

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

@ -87,4 +87,11 @@ test_that("Template methods work",
expect_true(is.list(tpllst) && length(tpllst) > 0)
})
test_that("Bad templates fail gracefully",
{
tplname <- paste(sample(letters, 10, replace=TRUE), collapse="")
template <- "../resources/template_bad.json"
expect_error(rg$deploy_template(tplname, template=template, wait=TRUE), "Unable to deploy template")
})
rg$delete(confirm=FALSE)