This script aggregates the test-related setup code from all test files.

library(googledrive)
source(testthat::test_path('helper.R'))
whoami <- drive_user()
whoami[c('displayName', 'emailAddress')]
## $displayName
## [1] "googledrive-testing@gargle-169921.iam.gserviceaccount.com"
## 
## $emailAddress
## [1] "googledrive-testing@gargle-169921.iam.gserviceaccount.com"
## change this to TRUE when you are really ready to do this!
SETUP <- TRUE

test-drive_cp.R

me_ <- nm_fun("TEST-drive-cp")
nm_ <- nm_fun("TEST-drive-cp", NULL)
if (SETUP) {
  drive_mkdir(nm_("i-am-a-folder"))
  drive_mkdir(nm_("not-unique-folder"))
  drive_mkdir(nm_("not-unique-folder"))
  drive_upload(
    system.file("DESCRIPTION"),
    nm_("i-am-a-file")
  )
}
## Created Drive file:
##   * i-am-a-folder-TEST-drive-cp: 1uIN9SdvRe4NRnaPQ4yMjIKjLR7hRlRKn
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * not-unique-folder-TEST-drive-cp: 1GelgvGvOMHTdibUEZiy_eHaq5uJyqdF_
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * not-unique-folder-TEST-drive-cp: 1LKQtwNpVhsa128tQU7q9pM0WROErzkKa
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * i-am-a-file-TEST-drive-cp: 1UuiG0tB-WulU-52VcKFnPRI8rihDmgAS
## with MIME type:
##   * text/plain

test-drive_create.R

me_ <- nm_fun("TEST-drive-create")
nm_ <- nm_fun("TEST-drive-create", NULL)
if (SETUP) {
  drive_mkdir(nm_("create-in-me"))
}
## Created Drive file:
##   * create-in-me-TEST-drive-create: 1fZGzg-9bDTAxU2kzkS2aj66xZyz9AYzp
## with MIME type:
##   * application/vnd.google-apps.folder

test-drive_download.R

nm_ <- nm_fun("TEST-drive-download", NULL)
if (SETUP) {
  drive_upload(system.file("DESCRIPTION"), nm_("DESC"))
  drive_upload(
    system.file("DESCRIPTION"),
    nm_("DESC-doc"),
    type = "document"
  )
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * DESC-TEST-drive-download: 1Bex0S3PvJiXHrhQtTXgfv4e0Z0M_0nYw
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * DESC-doc-TEST-drive-download: 1mK_i8fmduXYDaTlhT__CGGmTqgwNHhQ4WrCGP3Fr5jA
## with MIME type:
##   * application/vnd.google-apps.document

test-drive_find.R

me_ <- nm_fun("TEST-drive-find")
nm_ <- nm_fun("TEST-drive-find", NULL)
if (SETUP) {
  drive_mkdir(nm_("find-me"))
  drive_upload(
    system.file("DESCRIPTION"),
    nm_("copy-me")
  )
}
## Created Drive file:
##   * find-me-TEST-drive-find: 1N20sdn9zM7dcY6bvI7B0233PiGPQRU8M
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * copy-me-TEST-drive-find: 1cdC5-gCJXkgu55HB-2ssQBoBubBCMHZ-
## with MIME type:
##   * text/plain

test-drive_get.R

nm_ <- nm_fun("TEST-drive-get", NULL)
if (SETUP) {
  file_in_root <- drive_upload(
    system.file("DESCRIPTION"),
    name = nm_("thing01")
  )
  drive_upload(system.file("DESCRIPTION"), name = nm_("thing02"))
  drive_upload(system.file("DESCRIPTION"), name = nm_("thing03"))
  folder_in_root <- drive_mkdir(nm_("thing01"))
  folder_in_folder <- drive_mkdir(nm_("thing01"), parent = folder_in_root)
  file_in_folder_in_folder <- drive_cp(
    file_in_root,
    path = folder_in_folder,
    name = nm_("thing01")
  )
  drive_upload(
    system.file("DESCRIPTION"),
    path = folder_in_root,
    name = nm_("thing04")
  )

  folder_1_of_2 <- drive_mkdir(nm_("parent01"))
  folder_2_of_2 <- drive_mkdir(nm_("parent02"))
  child_of_2_parents <- drive_upload(
    system.file("DESCRIPTION"),
    path = folder_1_of_2,
    name = nm_("child_of_2_parents")
  )
  drive_update(child_of_2_parents, addParents = as_id(folder_2_of_2))
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * thing01-TEST-drive-get: 1VWqkIf3aiTHegtWfpxIfZpRQE-QYjG__
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * thing02-TEST-drive-get: 14Yra2rEwu3pjT1u628VNlGRX8nK3naVt
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * thing03-TEST-drive-get: 15Oizu8RGRBFknG86O__tlIyM-18wMM7i
## with MIME type:
##   * text/plain
## Created Drive file:
##   * thing01-TEST-drive-get: 1E1FSCIiHW-ZcrFmlaE1iJXRJwHNjFrFO
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * thing01-TEST-drive-get: 1-6CFKWjOJf65Sb0-kS54RFJpgSl33782
## with MIME type:
##   * application/vnd.google-apps.folder
## File copied:
##   * thing01-TEST-drive-get -> thing01-TEST-drive-get/thing01-TEST-drive-get
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * thing04-TEST-drive-get: 1zgASp1KK7U57LAgbbhoJho6Zs603f7eS
## with MIME type:
##   * text/plain
## Created Drive file:
##   * parent01-TEST-drive-get: 1uiA6pdPVVY09VTVPTaN1Bt6eCzExxV0T
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * parent02-TEST-drive-get: 1E8XU5u0InAJ-3ipSNOJdN8MAhfVXDRC4
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * child_of_2_parents-TEST-drive-get: 1zPWXyV8dmbFsj7bOuA0Vbbo5bodmtACC
## with MIME type:
##   * text/plain
## File updated:
##   * child_of_2_parents-TEST-drive-get: 1zPWXyV8dmbFsj7bOuA0Vbbo5bodmtACC

test-drive_ls.R

nm_ <- nm_fun("TEST-drive-ls", NULL)
if (SETUP) {
  drive_mkdir(nm_("list-me"))
  drive_upload(
    system.file("DESCRIPTION"),
    path = file.path(nm_("list-me"), nm_("DESCRIPTION"))
  )
  drive_upload(
    file.path(R.home("doc"), "html", "about.html"),
    path = file.path(nm_("list-me"), nm_("about-html"))
  )

  ## for testing `recursive = TRUE`
  top <- drive_mkdir(nm_("topdir"))
  drive_upload(
    system.file("DESCRIPTION"),
    path = top,
    name = nm_("apple"),
    type = "document",
    starred = TRUE
  )
  folder1_level1 <- drive_mkdir(nm_("folder1-level1"), parent = top)
  drive_mkdir(nm_("folder2-level1"), parent = top)
  x <- drive_upload(
    system.file("DESCRIPTION"),
    path = folder1_level1,
    name = nm_("banana"),
    type = "document"
  )
  folder1_level2 <- drive_mkdir(nm_("folder1-level2"), parent = folder1_level1)
  x <- drive_upload(
    system.file("DESCRIPTION"),
    path = folder1_level2,
    name = nm_("cranberry"),
    type = "document",
    starred = TRUE
  )
}
## Created Drive file:
##   * list-me-TEST-drive-ls: 1PfdiGK8-ZLkEyMiufqfREL13VeRaveS5
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * DESCRIPTION-TEST-drive-ls: 1TiI4BfsIg0yWxn8FpWYT1A-uDqpOKjGn
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/doc/html/about.html
## uploaded into Drive file:
##   * about-html-TEST-drive-ls: 1Ir-kGbTD4Mw5xk5EkaZEeRbqDirNXOPF
## with MIME type:
##   * text/html
## Created Drive file:
##   * topdir-TEST-drive-ls: 14D8Ra-hDRt3_ntWQwdpveBesTsyl966Z
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * apple-TEST-drive-ls: 13lSUVlSoRSJrGR6hGhbNrjCW5iut4mcKTJKlRHVXMAg
## with MIME type:
##   * application/vnd.google-apps.document
## Created Drive file:
##   * folder1-level1-TEST-drive-ls: 1JKa25Gp58cKrgZRl0KR8goXq0VDJf33e
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * folder2-level1-TEST-drive-ls: 1wGD4M_8qogUudGSZJ2quHCyjpZuRFXkP
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * banana-TEST-drive-ls: 1Ik5jAcQOmeE-mwbieUDpAu0d-S9RdtaOqxHmpu4zzk4
## with MIME type:
##   * application/vnd.google-apps.document
## Created Drive file:
##   * folder1-level2-TEST-drive-ls: 1FvlD0cwCIbOxl5ArBUiqbqQA9j8lNIWh
## with MIME type:
##   * application/vnd.google-apps.folder
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * cranberry-TEST-drive-ls: 1T54yfvfnGNj34Zhn0yuxwHFq0sWX0GHYZaR_6RgOqPk
## with MIME type:
##   * application/vnd.google-apps.document

test-drive_mkdir.R

me_ <- nm_fun("TEST-drive-mkdir")
nm_ <- nm_fun("TEST-drive-mkdir", NULL)
if (SETUP) {
  drive_mkdir(nm_("OMNI-PARENT"))
}
## Created Drive file:
##   * OMNI-PARENT-TEST-drive-mkdir: 1gfhRK8ZIBMWtM2XmoGjGWyqn1rvkKVU3
## with MIME type:
##   * application/vnd.google-apps.folder

test-drive_mv.R

me_ <- nm_fun("TEST-drive-mv")
nm_ <- nm_fun("TEST-drive-mv", NULL)
if (SETUP) {
  drive_mkdir(nm_("move-files-into-me"))
}
## Created Drive file:
##   * move-files-into-me-TEST-drive-mv: 1nwM4yy9MLmGvJvEyZU2nKw7eGH96Gc0K
## with MIME type:
##   * application/vnd.google-apps.folder

test-drive_publish.R

nm_ <- nm_fun("TEST-drive-publish", NULL)
if (SETUP) {
  drive_upload(
    file.path(R.home("doc"), "html", "about.html"),
    name = nm_("foo_doc"),
    type = "document"
  )
  drive_upload(
    file.path(R.home("doc"), "BioC_mirrors.csv"),
    name = nm_("foo_sheet"),
    type = "spreadsheet"
  )
  drive_upload(
    file.path(R.home("doc"), "html", "RLogo.pdf"),
    name = nm_("foo_pdf")
  )
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/doc/html/about.html
## uploaded into Drive file:
##   * foo_doc-TEST-drive-publish: 1H1qTWStEqygIHZeoCVcZHP715xzjFXCAeMj7t2z9pNM
## with MIME type:
##   * application/vnd.google-apps.document
## Local file:
##   * /Library/Frameworks/R.framework/Resources/doc/BioC_mirrors.csv
## uploaded into Drive file:
##   * foo_sheet-TEST-drive-publish: 1LloA7kTwmGYv77SaVX_NhO1ATzhEHxp7_wy3ZMBJB18
## with MIME type:
##   * application/vnd.google-apps.spreadsheet
## Local file:
##   * /Library/Frameworks/R.framework/Resources/doc/html/RLogo.pdf
## uploaded into Drive file:
##   * foo_pdf-TEST-drive-publish: 1Pmkk5NOyYQH9eqSEJUpUXvNRuN37GiO5
## with MIME type:
##   * application/pdf

test-drive_share.R

me_ <- nm_fun("TEST-drive-share")
nm_ <- nm_fun("TEST-drive-share", NULL)
if (SETUP) {
  drive_upload(system.file("DESCRIPTION"), nm_("DESC"))
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * DESC-TEST-drive-share: 1MVQQHkC03L9C1F5WHLU5lLPXB-Ach9kk
## with MIME type:
##   * text/plain

test-drive_trash.R

me_ <- nm_fun("TEST-drive-trash")
nm_ <- nm_fun("TEST-drive-trash", NULL)
if (SETUP) {
  drive_upload(
    system.file("DESCRIPTION"),
    nm_("trash-fodder")
  )
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * trash-fodder-TEST-drive-trash: 1Lhi37FUBqCYch3kUOiV40vpKWEmpAp7P
## with MIME type:
##   * text/plain

test-drive_update.R

me_ <- nm_fun("TEST-drive-update")
nm_ <- nm_fun("TEST-drive-update", NULL)
if (SETUP) {
  drive_upload(system.file("DESCRIPTION"), nm_("update-fodder"))
  drive_upload(system.file("DESCRIPTION"), nm_("not-unique"))
  drive_upload(system.file("DESCRIPTION"), nm_("not-unique"))
}
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * update-fodder-TEST-drive-update: 1KG5kRTmDxFmwNVb63QdwFSVetGgpzkig
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * not-unique-TEST-drive-update: 1m-tGFLqw1gk0tyYfXWtPWYCkEyjSzkNk
## with MIME type:
##   * text/plain
## Local file:
##   * /Library/Frameworks/R.framework/Resources/library/base/DESCRIPTION
## uploaded into Drive file:
##   * not-unique-TEST-drive-update: 1LGjhIAk_5V2cDuATfsjmFXvDL5efLClY
## with MIME type:
##   * text/plain

test-drive_upload.R

me_ <- nm_fun("TEST-drive-upload")
nm_ <- nm_fun("TEST-drive-upload", NULL)
if (SETUP) {
  drive_mkdir(nm_("upload-into-me"))
  drive_mkdir(nm_("upload-into-me-too"))
}
## Created Drive file:
##   * upload-into-me-TEST-drive-upload: 1v5LNdGlZZCTW16ZwrHY6OXzlzA000dhY
## with MIME type:
##   * application/vnd.google-apps.folder
## Created Drive file:
##   * upload-into-me-too-TEST-drive-upload: 1YiFII2fzc6tqENoFmXQWRIRuxttMGpjT
## with MIME type:
##   * application/vnd.google-apps.folder