Skip to content

Commit

Permalink
Merge pull request #26 from juliasilge/project-name-from-uuid
Browse files Browse the repository at this point in the history
Use uuids when generating CodeBuild project name
  • Loading branch information
DyfanJones committed May 3, 2023
2 parents d58dba0 + cf21452 commit 943cda4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Imports:
paws.security.identity,
zip,
stats,
utils
utils,
uuid
Suggests:
covr,
crayon,
Expand Down
13 changes: 2 additions & 11 deletions R/code_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ codebuild_project_init <- function(s3_location,
} else {
project_name_prefix
})
metadata$project_name <- paste0(
project_name_prefix,
paste(
sample(c(letters, LETTERS), size = 16, replace = T),
collapse = ""
)
)
metadata$project_name <- paste0(project_name_prefix, uuid::UUIDgenerate())
if (is.null(metadata$repo_name)) {
metadata$repo_name <- sprintf(
"sagemaker-studio-%s",
Expand All @@ -53,10 +47,7 @@ codebuild_project_init <- function(s3_location,
} else {
metadata$project_name <- paste0(
"sagemaker-studio-image-build-",
paste(
sample(c(letters, LETTERS), size = 16, replace = T),
collapse = ""
)
uuid::UUIDgenerate()
)
if (is.null(metadata$repo_name)) {
metadata$repo_name <- "sagemaker-studio"
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-code-build.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("check codebuild_project_init default", {
set.seed(123)
mock_get_studio_metadata <- mock2(list(domain_id = "foo", user_profile_name = "bar"))
mockery::stub(codebuild_project_init, ".get_studio_metadata", mock_get_studio_metadata)
mockery::stub(codebuild_project_init, "uuid::UUIDgenerate", "aaaa-bbbb-cccc")
actual <- codebuild_project_init("mybucket/location", "dummy")
expect_equal(
actual, list(
Expand All @@ -10,34 +10,34 @@ test_that("check codebuild_project_init default", {
s3_location = "mybucket/location",
role = "dummy",
compute_type = "BUILD_GENERAL1_SMALL",
project_name = "sagemaker-studio-foo-bar-EoYncPXQKZnyzAeY",
project_name = "sagemaker-studio-foo-bar-aaaa-bbbb-cccc",
repo_name = "sagemaker-studio-foo",
tag = "bar"
)
)
})

test_that("check codebuild_project_init default no studio metadata", {
set.seed(123)
mock_get_studio_metadata <- mock2(list())
mockery::stub(codebuild_project_init, ".get_studio_metadata", mock_get_studio_metadata)
mockery::stub(codebuild_project_init, "uuid::UUIDgenerate", "aaaa-bbbb-cccc")
actual <- codebuild_project_init("mybucket/location", "dummy")
expect_equal(
actual, list(
s3_location = "mybucket/location",
role = "dummy",
compute_type = "BUILD_GENERAL1_SMALL",
project_name = "sagemaker-studio-image-build-EoYncPXQKZnyzAeY",
project_name = "sagemaker-studio-image-build-aaaa-bbbb-cccc",
repo_name = "sagemaker-studio",
tag = "latest"
)
)
})

test_that("check codebuild_project_init with repo", {
set.seed(123)
mock_get_studio_metadata <- mock2(list())
mockery::stub(codebuild_project_init, ".get_studio_metadata", mock_get_studio_metadata)
mockery::stub(codebuild_project_init, "uuid::UUIDgenerate", "aaaa-bbbb-cccc")
actual <- codebuild_project_init("mybucket/location", "dummy", "my-repo:latest")
expect_equal(
actual, list(
Expand All @@ -46,7 +46,7 @@ test_that("check codebuild_project_init with repo", {
compute_type = "BUILD_GENERAL1_SMALL",
repo_name = "my-repo",
tag = "latest",
project_name = "sagemaker-studio-image-build-EoYncPXQKZnyzAeY"
project_name = "sagemaker-studio-image-build-aaaa-bbbb-cccc"
)
)
})
Expand All @@ -60,6 +60,7 @@ test_that("check codebuild_project_init long project_name_prefix", {
)
)
mockery::stub(codebuild_project_init, ".get_studio_metadata", mock_get_studio_metadata)
mockery::stub(codebuild_project_init, "uuid::UUIDgenerate", "aaaa-bbbb-cccc")
actual <- codebuild_project_init("mybucket/location", "dummy", "my-repo:latest")
expect_equal(
actual, list(
Expand All @@ -70,7 +71,7 @@ test_that("check codebuild_project_init long project_name_prefix", {
compute_type = "BUILD_GENERAL1_SMALL",
repo_name = "my-repo",
tag = "latest",
project_name = "sagemaker-studio-osncjrvketnvyzesyyichzgjisdnqkgulojmgiijwugufybehlmrayyfuoiozptfkhvvgpqvrqbdmevsytvynywchplyncngcwvzouehsjrjlbjvltnqnvchnsoxqwkgowzfngjefpxuwkdlnsygvzigbpmsxtogdahtypxvkpthcdtlvqjtkywhnumbkmnfyhlzdmnu-pwahhjyhruiggzjxvwzkXlUYfposcTGGVkJR"
project_name = "sagemaker-studio-osncjrvketnvyzesyyichzgjisdnqkgulojmgiijwugufybehlmrayyfuoiozptfkhvvgpqvrqbdmevsytvynywchplyncngcwvzouehsjrjlbjvltnqnvchnsoxqwkgowzfngjefpxuwkdlnsygvzigbpmsxtogdahtypxvkpthcdtlvqjtkywhnumbkmnfyhlzdmnu-pwahhjyhruiggzjxvwzkaaaa-bbbb-cccc"
)
)
})
Expand Down

0 comments on commit 943cda4

Please sign in to comment.