Skip to content

Commit

Permalink
vpc code: fix misspelled fxn name, better error handling, more tests …
Browse files Browse the repository at this point in the history
…for vpc fxn
  • Loading branch information
sckott committed Apr 8, 2024
1 parent bbba9c1 commit 7d6b41d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 40 deletions.
5 changes: 3 additions & 2 deletions R/vpc_security_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' and [aws_vpc_security_group_ingress()]
#' @family security groups
#' @return (character) security group ID
aws_vpc_sg_with_ingresss <- function(engine) {
aws_vpc_sg_with_ingress <- function(engine) {
sg <- aws_vpc_security_group_create(
name = glue("{engine}-{paste0(sample(1:9, size = 4), collapse = '')}"),
engine = engine
Expand Down Expand Up @@ -39,6 +39,7 @@ security_group_handler <- function(ids, engine) {
sgsdf <- jsonlite::fromJSON(
jsonlite::toJSON(sgs$SecurityGroups, auto_unbox = TRUE)
)
if (is_empty(sgsdf)) sgsdf <- tibble(IpPermissions = list())

port_df <- dplyr::filter(
sgsdf,
Expand All @@ -56,7 +57,7 @@ security_group_handler <- function(ids, engine) {
"Creating security group with access for ",
"{.strong {engine}} and port {.strong {port}}"
))
trysg <- tryCatch(aws_vpc_sg_with_ingresss(engine),
trysg <- tryCatch(aws_vpc_sg_with_ingress(engine),
error = function(e) e
)
if (rlang::is_error(trysg)) {
Expand Down
2 changes: 1 addition & 1 deletion man/aws_vpc_sec_group_rules.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aws_vpc_security_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aws_vpc_security_group_create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aws_vpc_security_group_ingress.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/aws_vpc_security_groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 0 additions & 33 deletions man/aws_vpc_sg_with_ingresss.Rd

This file was deleted.

29 changes: 29 additions & 0 deletions tests/testthat/test-vpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,34 @@ test_that("aws_vpc_security_group_ingress", {
expect_match(out$SecurityGroupRules[[1]]$GroupId, "sg-")
})

test_that("aws_vpc_sg_with_ingress", {
expect_error(aws_vpc_sg_with_ingress())

res <- aws_vpc_sg_with_ingress("mariadb")
expect_type(res, "character")
expect_match(res, "sg-")

out <- aws_vpc_security_group(res)
expect_type(out, "list")
expect_length(out$SecurityGroups, 1)
expect_match(out$SecurityGroups[[1]]$GroupName, "mariadb-")

res_mysql <- aws_vpc_sg_with_ingress("mysql")
out_mysql <- aws_vpc_security_group(res_mysql)
expect_match(out_mysql$SecurityGroups[[1]]$GroupName, "mysql-")
})

test_that("security_group_handler", {
# missing `id` param
expect_error(security_group_handler())
# if `id` given and not `NULL`, returns itself
an_id <- 123
expect_equal(security_group_handler(an_id), an_id)
# if `id` given and IS `NULL`, errors b/c `engine` missing
expect_error(security_group_handler(NULL))
# if `id` given, engine value not supported
expect_error(security_group_handler(NULL, engine = "asdff"))
})

# cleanup
Sys.unsetenv("AWS_PROFILE")

0 comments on commit 7d6b41d

Please sign in to comment.