tests/testthat/setup-env.R

if (gargle:::secret_can_decrypt("retl")) {
  message("Can decrypt retl")
  json <- gargle:::secret_read(package = "retl", name = "retl-testing.json")
  bigrquery::bq_auth(path = rawToChar(json))
  googleCloudStorageR::gcs_auth(json_file = rawToChar(json))
  googlesheets4::gs4_auth(path = rawToChar(json))

  ds <- bigrquery::bq_test_dataset(location = bqDefaultLocation())
  Sys.setenv(GCS_BUCKET = "madecom-test-retl")
  Sys.setenv(BIGQUERY_DATASET = ds$dataset)
  Sys.setenv(BIGQUERY_PROJECT = Sys.getenv("BIGQUERY_TEST_PROJECT"))
  Sys.setenv(DOUBLECLICK_SEGMATATION_TYPE = "FLOODLIGHT")
  Sys.setenv(DOUBLECLICK_SEGMATATION_NAME = "ML")
  Sys.setenv(BIGQUERY_LOCATION = "US")
  if (!bqDatasetExists()) {
    print("Created test dataset")
    bqCreateDataset()
  }
} else {
  stop("Cannot decrypt retl")
}
madedotcom/retl documentation built on Sept. 19, 2022, 3:28 a.m.