From dc23bc33000f37104e0349ddf6adc8b54c90aefb Mon Sep 17 00:00:00 2001 From: Mark IIH Date: Mon, 29 Jul 2019 16:15:27 +0200 Subject: [PATCH] add more tests --- tests/testthat/test-gcs.R | 68 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-gcs.R b/tests/testthat/test-gcs.R index 3b3a43f..a2a71c7 100644 --- a/tests/testthat/test-gcs.R +++ b/tests/testthat/test-gcs.R @@ -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) + }) \ No newline at end of file