Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark IIH committed Jul 29, 2019
1 parent 905a43f commit dc23bc3
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions tests/testthat/test-gcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,74 @@ test_that("Authentication", {
expect_true(googleAuthR::gar_has_token())
})

test_that("Buckets", {
b <- gcs_list_buckets("iih-tools-analytics")
test_that("Bucket List", {
googleAuthR::skip_if_no_env_auth(
"GCS_DEFAULT_PROJECT"
)

proj <- Sys.getenv("GCS_DEFAULT_PROJECT")
expect_true(proj != "")
b <- gcs_list_buckets(proj)

expect_s3_class(b, "data.frame")
expect_true(
all(names(b) %in% c("name","storageClass","location","updated"))
)
})

test_that("Bucket Operations", {
googleAuthR::skip_if_no_env_auth(
"GCS_DEFAULT_BUCKET"
)

buck <- Sys.getenv("GCS_DEFAULT_BUCKET")
expect_true(buck != "")
expect_true(buck == gcs_get_global_bucket())

b <- gcs_get_bucket(buck)

expect_equal(b$kind, "storage#bucket")
})

test_that("Object Operations", {
googleAuthR::skip_if_no_env_auth(
"GCS_DEFAULT_BUCKET"
)

buck <- Sys.getenv("GCS_DEFAULT_BUCKET")

bs <- gcs_list_objects(bucket = buck)
expect_s3_class(bs, "data.frame")
expect_true(
all(names(bs) %in% c("name","size","updated"))
)

bs2 <- gcs_list_objects(bucket = buck, detail = "more")
expect_s3_class(bs2, "data.frame")
expect_true(
all(names(bs2) %in% c("name",
"size",
"bucket",
"contentType",
"timeCreated",
"updated",
"storageClass"))
)

bs3 <- gcs_list_objects(bucket = buck, detail = "full")
expect_s3_class(bs3, "data.frame")
expect_true(
all(names(bs3) %in% c('id', 'selfLink', 'name', 'bucket', 'generation',
'metageneration', 'timeCreated', 'updated',
'storageClass', 'timeStorageClassUpdated',
'size', 'md5Hash', 'mediaLink', 'crc32c',
'etag', 'contentType',
'componentCount', 'contentLanguage'))
)

mtcars <- gcs_get_object("mtcars.csv", bucket = buck)
expect_s3_class(mtcars, "data.frame")

mtcars_meta <- gcs_get_object("mtcars.csv", bucket = buck, meta = TRUE)

})

0 comments on commit dc23bc3

Please sign in to comment.