diff --git a/.vsts/pipeline.yml b/.vsts/pipeline.yml new file mode 100644 index 0000000..d835261 --- /dev/null +++ b/.vsts/pipeline.yml @@ -0,0 +1,41 @@ +name: $(Build.SourceBranch)$(Rev:.r) + +trigger: + - master + +resources: + containers: + - container: linux + image: ubuntu:16.04 + +jobs: +- job: Build + displayName: Build Job + condition: succeeded() + pool: + vmImage: 'ubuntu-16.04' + steps: + - task: ShellScript@2 + displayName: Build + inputs: + scriptPath: 'tests/test_scripts/build.sh' + + - script: | + touch ~/.Rprofile + echo "Sys.setenv(BATCH_ACCOUNT_NAME ='"$(BATCH_ACCOUNT_NAME)"');" >> ~/.Rprofile + echo "Sys.setenv(BATCH_ACCOUNT_KEY ='"$(BATCH_ACCOUNT_KEY)"');" >> ~/.Rprofile + echo "Sys.setenv(BATCH_ACCOUNT_URL ='"$(BATCH_ACCOUNT_URL)"');" >> ~/.Rprofile + echo "Sys.setenv(STORAGE_ACCOUNT_NAME ='"$(STORAGE_ACCOUNT_NAME)"');" >> ~/.Rprofile + echo "Sys.setenv(STORAGE_ACCOUNT_KEY ='"$(STORAGE_ACCOUNT_KEY)"');" >> ~/.Rprofile + sudo R \ + -e "getwd()" \ + -e "devtools::install()" \ + -e "devtools::build()" \ + -e "doAzureParallel::generateCredentialsConfig('test_credentials.json', batchAccountName = Sys.getenv('BATCH_ACCOUNT_NAME'), batchAccountKey = Sys.getenv('BATCH_ACCOUNT_KEY'), batchAccountUrl = Sys.getenv('BATCH_ACCOUNT_URL'), storageAccountName = Sys.getenv('STORAGE_ACCOUNT_NAME'), storageAccountKey = Sys.getenv('STORAGE_ACCOUNT_KEY'))" + condition: succeeded() + displayName: Create R Profile Environment Setting + + - task: ShellScript@2 + displayName: Run Unit Tests + inputs: + scriptPath: 'tests/testthat/unit_tests/unit_tests.sh' diff --git a/samples/long_running_job/long_running_job.R b/samples/async_job/async_job_example.R similarity index 100% rename from samples/long_running_job/long_running_job.R rename to samples/async_job/async_job_example.R diff --git a/samples/azure_files/azure_files.r b/samples/azure_files/azure_files_example.r similarity index 100% rename from samples/azure_files/azure_files.r rename to samples/azure_files/azure_files_example.r diff --git a/samples/caret/cluster-caret.json b/samples/caret/caret_cluster.json similarity index 100% rename from samples/caret/cluster-caret.json rename to samples/caret/caret_cluster.json diff --git a/samples/caret/caret_example.R b/samples/caret/caret_example.R index f8da4db..f612c96 100644 --- a/samples/caret/caret_example.R +++ b/samples/caret/caret_example.R @@ -17,10 +17,10 @@ generateCredentialsConfig("credentials.json") setCredentials("credentials.json") # generate cluster config json file -generateClusterConfig("cluster-caret.json") +generateClusterConfig("caret_cluster.json") # Creating an Azure parallel backend -cluster <- makeCluster(cluster = "cluster-caret.json") +cluster <- makeCluster("caret_cluster.json") # Register your Azure parallel backend to the foreach implementation registerDoAzureParallel(cluster) @@ -33,7 +33,7 @@ registerDoAzureParallel(cluster) # https://topepo.github.io/caret/index.html library(caret) -# Set your chunk size of your tasks to 8 +# Set the chunk size of your tasks to 8 # So that caret knows in group tasks into larger chunks setChunkSize(8) @@ -41,10 +41,10 @@ setChunkSize(8) install.packages("DAAG") library(DAAG) -# 'spam7' is a data set that consists of 4601 email items, -# of which 1813 items were identified as spam. This sample -# has 7 features, one of which is titled 'yesno'. In this -# example, we will be classifying our data into 'yesno' to +# 'spam7' is a data set that consists of 4601 email items, +# of which 1813 items were identified as spam. This sample +# has 7 features, one of which is titled 'yesno'. In this +# example, we will be classifying our data into 'yesno' to # identify which rows are spam, and which are not. # split the data into training and testing @@ -53,7 +53,7 @@ inTraining <- createDataPartition(spam7$yesno, p = .75, list = FALSE) training <- spam7[ inTraining,] testing <- spam7[-inTraining,] -# Define the settings for the cv. Because we have already +# Define the settings for the cv. Because we have already # registered our parallel backend, Caret will know to use it fitControl <- trainControl(## 10-fold cross validation method = "repeatedcv", @@ -68,9 +68,9 @@ fitControl <- trainControl(## 10-fold cross validation rf_fit <- train(## classification column - yesno ~ ., + yesno ~ ., ## dataframe to train on - data = training, + data = training, ## model to use - other models are also available (see caret documentation) method = "rf", ## the metric to use for evaluation diff --git a/samples/mandelbrot/mandelbrot.R b/samples/mandelbrot/mandelbrot_example.R similarity index 100% rename from samples/mandelbrot/mandelbrot.R rename to samples/mandelbrot/mandelbrot_example.R diff --git a/samples/package_management/bioconductor/package_management_cluster.json b/samples/package_management/bioconductor/bioconductor_cluster.json similarity index 92% rename from samples/package_management/bioconductor/package_management_cluster.json rename to samples/package_management/bioconductor/bioconductor_cluster.json index 157ca86..36921e5 100644 --- a/samples/package_management/bioconductor/package_management_cluster.json +++ b/samples/package_management/bioconductor/bioconductor_cluster.json @@ -1,5 +1,5 @@ { - "name": "package_management", + "name": "bioconductor_pool", "vmSize": "Standard_A2_v2", "maxTasksPerNode": 1, "poolSize": { diff --git a/samples/package_management/bioconductor/bioconductor.r b/samples/package_management/bioconductor/bioconductor_example.R similarity index 100% rename from samples/package_management/bioconductor/bioconductor.r rename to samples/package_management/bioconductor/bioconductor_example.R diff --git a/samples/package_management/custom/README.md b/samples/package_management/custom_packages/README.md similarity index 100% rename from samples/package_management/custom/README.md rename to samples/package_management/custom_packages/README.md diff --git a/samples/package_management/custom/custom_packages_cluster.json b/samples/package_management/custom_packages/custom_packages_cluster.json similarity index 100% rename from samples/package_management/custom/custom_packages_cluster.json rename to samples/package_management/custom_packages/custom_packages_cluster.json diff --git a/samples/package_management/custom/custom.R b/samples/package_management/custom_packages/custom_packages_example.R similarity index 100% rename from samples/package_management/custom/custom.R rename to samples/package_management/custom_packages/custom_packages_example.R diff --git a/tests/test_scripts/build.sh b/tests/test_scripts/build.sh new file mode 100644 index 0000000..6b9ef77 --- /dev/null +++ b/tests/test_scripts/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list + +gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 +gpg -a --export E084DAB9 | sudo apt-key add - + +sudo apt-get update +sudo apt-get install -y r-base r-base-dev libcurl4-openssl-dev +sudo apt-get install -y libssl-dev libxml2-dev libgdal-dev libproj-dev libgsl-dev + +sudo R \ + -e "getwd();" \ + -e "install.packages(c('devtools', 'remotes', 'testthat', 'roxygen2'));" diff --git a/tests/test_scripts/test.sh b/tests/test_scripts/test.sh deleted file mode 100644 index 1a51726..0000000 --- a/tests/test_scripts/test.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list - -gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 -gpg -a --export E084DAB9 | sudo apt-key add - - -sudo apt-get update -sudo apt-get install -y r-base r-base-dev libcurl4-openssl-dev -sudo apt-get install -y libssl-dev libxml2-dev libgdal-dev libproj-dev libgsl-dev - -sudo R \ - -e "Sys.setenv(BATCH_ACCOUNT_NAME = '$BATCH_ACCOUNT_NAME')" \ - -e "Sys.setenv(BATCH_ACCOUNT_KEY = '$BATCH_ACCOUNT_KEY')" \ - -e "Sys.setenv(BATCH_ACCOUNT_URL = '$BATCH_ACCOUNT_URL')" \ - -e "Sys.setenv(STORAGE_ACCOUNT_NAME = '$STORAGE_ACCOUNT_NAME')" \ - -e "Sys.setenv(STORAGE_ACCOUNT_KEY = '$STORAGE_ACCOUNT_KEY')" \ - -e "getwd();" \ - -e "install.packages(c('devtools', 'remotes', 'testthat', 'roxygen2'));" \ - -e "devtools::install();" \ - -e "devtools::build();" \ - -e "res <- devtools::test(reporter='summary');" \ - -e "df <- as.data.frame(res);" \ - -e "if(sum(df[['failed']]) > 0 || any(df[['error']])) { q(status=1) }" diff --git a/tests/testthat/core/test-cluster.R b/tests/testthat/core/test-cluster.R new file mode 100644 index 0000000..29c4238 --- /dev/null +++ b/tests/testthat/core/test-cluster.R @@ -0,0 +1,81 @@ +context("Cluster Management Test") + +test_that("Create Cluster Test", { + testthat::skip_on_travis() + source("utility.R") + + settings <- getSettings() + cluster <- + doAzureParallel::makeCluster(settings$clusterConfig, wait = FALSE) + + cluster <- getCluster(cluster$poolId) + clusterList <- getClusterList() + filter <- list() + filter$state <- c("active", "deleting") + + testthat::expect_true('test-pool' %in% clusterList$Id) +}) + +test_that("Get Cluster Test", { + testthat::skip_on_travis() + source("utility.R") + + settings <- getSettings() + + cluster <- + doAzureParallel::makeCluster(settings$clusterConfig, wait = FALSE) + + cluster <- getCluster(cluster$poolId) + clusterList <- getClusterList() + filter <- list() + filter$state <- c("active", "deleting") + + testthat::expect_true('test-pool' %in% clusterList$Id) + + clusterList <- getClusterList(filter) + + for (i in 1:length(clusterList$State)) { + testthat::expect_true(clusterList$State[i] == 'active' || + clusterList$State[i] == 'deleting') + } +}) + +test_that("Autoscale Cluster Test", { + testthat::skip_on_travis() + source("utility.R") + + settings <- getSettings() + + cluster <- + doAzureParallel::makeCluster(settings$clusterConfig, wait = FALSE) + + cluster <- getCluster(cluster$poolId) + clusterList <- getClusterList() + filter <- list() + filter$state <- c("active", "deleting") + + testthat::expect_true('test-pool' %in% clusterList$Id) + + clusterList <- getClusterList(filter) + + for (i in 1:length(clusterList$State)) { + testthat::expect_true(clusterList$State[i] == 'active' || + clusterList$State[i] == 'deleting') + } +}) + +test_that("Delete Cluster Test", { + testthat::skip_on_travis() + source("utility.R") + + settings <- getSettings() + + cluster <- + doAzureParallel::makeCluster(settings$clusterConfig, wait = FALSE) + + doAzureParallel::stopCluster(cluster) + + testthat::expect_true('test-pool' %in% clusterList$Id) + + clusterList <- getClusterList(filter) +}) diff --git a/tests/testthat/test-autodeletejob.R b/tests/testthat/integration_tests/test-autodeletejob.R similarity index 100% rename from tests/testthat/test-autodeletejob.R rename to tests/testthat/integration_tests/test-autodeletejob.R diff --git a/tests/testthat/test-error-handling.R b/tests/testthat/integration_tests/test-error-handling.R similarity index 83% rename from tests/testthat/test-error-handling.R rename to tests/testthat/integration_tests/test-error-handling.R index 3d71574..824f3cb 100644 --- a/tests/testthat/test-error-handling.R +++ b/tests/testthat/integration_tests/test-error-handling.R @@ -4,9 +4,6 @@ test_that("Remove error handling with combine test", { source("utility.R") settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) @@ -31,9 +28,6 @@ test_that("Remove error handling test", { source("utility.R") settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - settings$clusterConfig$poolId <- "error-handling-test" cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) @@ -58,9 +52,6 @@ test_that("Pass error handling test", { source("utility.R") settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - settings$clusterConfig$poolId <- "error-handling-test" cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) @@ -82,14 +73,10 @@ test_that("Pass error handling test", { }) test_that("Stop error handling test", { - testthat::skip("Manual Test") testthat::skip_on_travis() source("utility.R") settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - settings$clusterConfig$poolId <- "error-handling-test" cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) @@ -99,11 +86,7 @@ test_that("Stop error handling test", { testthat::expect_error( res <- foreach::foreach(i = 1:4, .errorhandling = "stop") %dopar% { - if (i == 2) { - randomObject - } - - i + randomObject } ) }) diff --git a/tests/testthat/test-foreach-options.R b/tests/testthat/integration_tests/test-foreach.R similarity index 62% rename from tests/testthat/test-foreach-options.R rename to tests/testthat/integration_tests/test-foreach.R index ec864cf..efd084f 100644 --- a/tests/testthat/test-foreach-options.R +++ b/tests/testthat/integration_tests/test-foreach.R @@ -1,12 +1,31 @@ -context("foreach options test") +context("Integration Test") + +# Run this test for users to make sure the core features +# of doAzureParallel are still working +test_that("simple foreach 1 to 4", { + testthat::skip_on_travis() + source("utility.R") + settings <- getSettings() + doAzureParallel::registerDoAzureParallel(cluster) + + '%dopar%' <- foreach::'%dopar%' + res <- + foreach::foreach(i = 1:4) %dopar% { + i + } + + res <- unname(res) + + testthat::expect_equal(length(res), 4) + testthat::expect_equal(res, list(1, 2, 3, 4)) +}) + +context("Foreach Options Integration Test") test_that("chunksize", { testthat::skip_on_travis() source("utility.R") settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) diff --git a/tests/testthat/test-local-merge.R b/tests/testthat/integration_tests/test-local-merge.R similarity index 54% rename from tests/testthat/test-local-merge.R rename to tests/testthat/integration_tests/test-local-merge.R index 94f7e7c..5112cb7 100644 --- a/tests/testthat/test-local-merge.R +++ b/tests/testthat/integration_tests/test-local-merge.R @@ -5,12 +5,42 @@ test_that("merge job result locally test", { testthat::skip_on_travis() testthat::skip("Skipping merge job locally") source("utility.R") - settings <- gettingSettings() settings <- getSettings() - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - + cluster <- doAzureParallel::makeCluster(settings$clusterConfig) + doAzureParallel::registerDoAzureParallel(cluster) + + setChunkSize(2) + '%dopar%' <- foreach::'%dopar%' + jobId <- + foreach::foreach( + i = 1:11, + .errorhandling = "pass", + .options.azure = list( + enableCloudCombine = FALSE, + wait = FALSE + ) + ) %dopar% { + i + } + + res <- getJobResult(jobId) + + testthat::expect_equal(length(res), + 10) + + for (i in 1:10) { + testthat::expect_equal(res[[i]], + i) + } +}) + +test_that("merge job result locally test", { + testthat::skip_on_travis() + testthat::skip("Skipping merge job locally") + source("utility.R") + settings <- getSettings() + cluster <- doAzureParallel::makeCluster(settings$clusterConfig) doAzureParallel::registerDoAzureParallel(cluster) diff --git a/tests/testthat/test-long-running-job.R b/tests/testthat/integration_tests/test-long-running-job.R similarity index 100% rename from tests/testthat/test-long-running-job.R rename to tests/testthat/integration_tests/test-long-running-job.R diff --git a/tests/testthat/test-package-installation-bioc.R b/tests/testthat/integration_tests/test-package-installation-bioc.R similarity index 100% rename from tests/testthat/test-package-installation-bioc.R rename to tests/testthat/integration_tests/test-package-installation-bioc.R diff --git a/tests/testthat/test-package-installation-github.R b/tests/testthat/integration_tests/test-package-installation-github.R similarity index 100% rename from tests/testthat/test-package-installation-github.R rename to tests/testthat/integration_tests/test-package-installation-github.R diff --git a/tests/testthat/test-async-cluster.R b/tests/testthat/test-async-cluster.R deleted file mode 100644 index 9f55846..0000000 --- a/tests/testthat/test-async-cluster.R +++ /dev/null @@ -1,27 +0,0 @@ -context("Cluster Management Test") -test_that("Get Cluster List / Get Cluster test", { - testthat::skip_on_travis() - source("utility.R") - - settings <- getSettings() - - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - - cluster <- - doAzureParallel::makeCluster(settings$clusterConfig, wait = FALSE) - - cluster <- getCluster(cluster$poolId) - clusterList <- getClusterList() - filter <- list() - filter$state <- c("active", "deleting") - - testthat::expect_true('test-pool' %in% clusterList$Id) - - clusterList <- getClusterList(filter) - - for (i in 1:length(clusterList$State)) { - testthat::expect_true(clusterList$State[i] == 'active' || - clusterList$State[i] == 'deleting') - } -}) diff --git a/tests/testthat/test-live.R b/tests/testthat/test-live.R deleted file mode 100644 index b42df6a..0000000 --- a/tests/testthat/test-live.R +++ /dev/null @@ -1,26 +0,0 @@ -context("Integration Test") - -# Run this test for users to make sure the core features -# of doAzureParallel are still working -test_that("simple foreach 1 to 4", { - testthat::skip_on_travis() - source("utility.R") - settings <- getSettings() - - # set your credentials - doAzureParallel::setCredentials(settings$credentials) - - cluster <- doAzureParallel::makeCluster(settings$clusterConfig) - doAzureParallel::registerDoAzureParallel(cluster) - - '%dopar%' <- foreach::'%dopar%' - res <- - foreach::foreach(i = 1:4) %dopar% { - i - } - - res <- unname(res) - - testthat::expect_equal(length(res), 4) - testthat::expect_equal(res, list(1, 2, 3, 4)) -}) diff --git a/tests/testthat/test-cluster-config.R b/tests/testthat/unit_tests/test-cluster-config.R similarity index 83% rename from tests/testthat/test-cluster-config.R rename to tests/testthat/unit_tests/test-cluster-config.R index b9a4eae..dd8d7cb 100644 --- a/tests/testthat/test-cluster-config.R +++ b/tests/testthat/unit_tests/test-cluster-config.R @@ -1,6 +1,6 @@ context("validating cluster config") -test_that("validating a cluster config file with null pool property", { +test_that("generateClusterConfig_NullPoolValue_Success", { clusterConfig <- "badcluster.json" generateClusterConfig(clusterConfig) @@ -11,7 +11,7 @@ test_that("validating a cluster config file with null pool property", { on.exit(file.remove(clusterConfig)) }) -test_that("validating a cluster config file with bad autoscale formula property", { +test_that("generateClusterConfig_BadAutoscaleFormula_Failed", { clusterConfig <- "badcluster.json" generateClusterConfig(clusterConfig) @@ -27,7 +27,7 @@ test_that("validating a cluster config file with bad autoscale formula property" }) -test_that("validating a cluster config file with incorrect data types", { +test_that("generateClusterConfig_InvalidDataTypes_Failed", { clusterConfig <- "badcluster.json" generateClusterConfig(clusterConfig) @@ -43,7 +43,7 @@ test_that("validating a cluster config file with incorrect data types", { on.exit(file.remove(clusterConfig)) }) -test_that("validating a cluster config file with null values", { +test_that("generateClusterConfig_NullValues_Failed", { clusterConfig <- "nullcluster.json" generateClusterConfig(clusterConfig) diff --git a/tests/testthat/test-command-line.R b/tests/testthat/unit_tests/test-command-line.R similarity index 77% rename from tests/testthat/test-command-line.R rename to tests/testthat/unit_tests/test-command-line.R index d70b8e0..0ed11dc 100644 --- a/tests/testthat/test-command-line.R +++ b/tests/testthat/unit_tests/test-command-line.R @@ -1,12 +1,12 @@ context("linux wrap commands") -test_that("single command on command line", { +test_that("linuxWrapCommands_SingleCommand_Success", { commandLine <- linuxWrapCommands("ls") expect_equal(commandLine, "/bin/bash -c \"set -e; set -o pipefail; ls; wait\"") }) -test_that("multiple commands on command line", { +test_that("linuxWrapCommands_MultipleCommand_Success", { commands <- c("ls", "echo \"hello\"", "cp origfile newfile") commandLine <- linuxWrapCommands(commands) diff --git a/tests/testthat/test-output-files.R b/tests/testthat/unit_tests/test-output-files.R similarity index 86% rename from tests/testthat/test-output-files.R rename to tests/testthat/unit_tests/test-output-files.R index 46c375e..e7f03e9 100644 --- a/tests/testthat/test-output-files.R +++ b/tests/testthat/unit_tests/test-output-files.R @@ -1,6 +1,6 @@ context("creating output files") -test_that("verify output file properties", { +test_that("createOutputFile_FileProperties_Success", { fakeUrl <- "https://accountname.blob.core.windows.net/outputs?se=2017-07-31&sr=c&st=2017-07-12" @@ -12,7 +12,7 @@ test_that("verify output file properties", { }) -test_that("create output file with null path", { +test_that("createOutputFile_NullValue_Success", { fakeUrl <- "https://accountname.blob.core.windows.net/outputs?se=2017-07-31&sr=c&st=2017-07-12" @@ -25,7 +25,7 @@ test_that("create output file with null path", { ) }) -test_that("create output file with multiple virtual directories", { +test_that("createOutputFile_MultipleVirtualDirectories_Success", { fakeUrl <- "https://accountname.blob.core.windows.net/outputs/foo/baz/bar?se=2017-07-31&sr=c&st=2017-07-12" diff --git a/tests/testthat/test-package-installation.R b/tests/testthat/unit_tests/test-package-installation.R similarity index 84% rename from tests/testthat/test-package-installation.R rename to tests/testthat/unit_tests/test-package-installation.R index 30b0a73..4dda3c0 100644 --- a/tests/testthat/test-package-installation.R +++ b/tests/testthat/unit_tests/test-package-installation.R @@ -1,5 +1,5 @@ context("Package Command Line Tests") -test_that("successfully create cran job package command line", { +test_that("getJobPackageInstallationCommand_Cran_Success", { jobInstallation <- getJobPackageInstallationCommand("cran", c("hts", "lubridate", "tidyr", "dplyr")) expect_equal( @@ -8,7 +8,7 @@ test_that("successfully create cran job package command line", { ) }) -test_that("successfully create github job package command line", { +test_that("getJobPackageInstallationCommand_Github_Success", { jobInstallation <- getJobPackageInstallationCommand("github", c("Azure/doAzureParallel", "Azure/rAzureBatch")) expect_equal( @@ -17,7 +17,7 @@ test_that("successfully create github job package command line", { ) }) -test_that("successfully create cran pool package command line", { +test_that("getPoolPackageInstallationCommand_Cran_Success", { poolInstallation <- getPoolPackageInstallationCommand("cran", c("hts", "lubridate", "tidyr")) expect_equal(length(poolInstallation), 1) @@ -36,7 +36,7 @@ test_that("successfully create cran pool package command line", { expect_equal(poolInstallation, expected) }) -test_that("successfully create github pool package command line", { +test_that("getPoolPackageInstallationCommand_Github_Success", { poolInstallation <- getPoolPackageInstallationCommand("github", c("Azure/doAzureParallel", "Azure/rAzureBatch")) expect_equal(length(poolInstallation), 1) @@ -55,7 +55,7 @@ test_that("successfully create github pool package command line", { expect_equal(poolInstallation, expected) }) -test_that("successfully create bioconductor pool package command line", { +test_that("getPoolPackageInstallationCommand_Bioconductor_Success", { poolInstallation <- getPoolPackageInstallationCommand("bioconductor", c("IRanges", "a4")) diff --git a/tests/testthat/test-set-credentials.R b/tests/testthat/unit_tests/test-set-credentials.R similarity index 92% rename from tests/testthat/test-set-credentials.R rename to tests/testthat/unit_tests/test-set-credentials.R index 86adfc1..88033cc 100644 --- a/tests/testthat/test-set-credentials.R +++ b/tests/testthat/unit_tests/test-set-credentials.R @@ -1,7 +1,7 @@ # Run this test for users to make sure the set credentials from json or R object features # of doAzureParallel are still working context("set credentials from R object scenario test") -test_that("set credentials/cluster config programmatically scenario test", { +test_that("setCredentials_Sdk_Success", { testthat::skip("Live test") testthat::skip_on_travis() @@ -47,7 +47,7 @@ test_that("set credentials/cluster config programmatically scenario test", { validation$isValidClusterConfig(clusterConfig) }) -test_that("set credentials/cluster config from Json file scenario test", { +test_that("SetCredentials_Json_Success", { testthat::skip("Live test") testthat::skip_on_travis() diff --git a/tests/testthat/unit-tests.R b/tests/testthat/unit_tests/unit-tests.R similarity index 100% rename from tests/testthat/unit-tests.R rename to tests/testthat/unit_tests/unit-tests.R diff --git a/tests/testthat/unit_tests/unit_tests.sh b/tests/testthat/unit_tests/unit_tests.sh new file mode 100644 index 0000000..e47df9d --- /dev/null +++ b/tests/testthat/unit_tests/unit_tests.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +sudo R \ + -e "getwd();" \ + -e "devtools::install();" \ + -e "devtools::build();" \ + -e "devtools::load_all();" \ + -e "res <- testthat::test_dir('.', reporter='summary');" \ + -e "df <- as.data.frame(res);" \ + -e "if(sum(df[['failed']]) > 0 || any(df[['error']])) { q(status=1) }" diff --git a/tests/testthat/utility.R b/tests/testthat/utility.R index 8afd9bd..e420253 100644 --- a/tests/testthat/utility.R +++ b/tests/testthat/utility.R @@ -3,25 +3,7 @@ getSettings <- function(dedicatedMin = 0, lowPriorityMin = 0, lowPriorityMax = 2, poolName = "test-pool"){ - list( - credentials = list( - "sharedKey" = list( - "batchAccount" = list( - "name" = Sys.getenv("BATCH_ACCOUNT_NAME"), - "key" = Sys.getenv("BATCH_ACCOUNT_KEY"), - "url" = Sys.getenv("BATCH_ACCOUNT_URL") - ), - "storageAccount" = list( - "name" = Sys.getenv("STORAGE_ACCOUNT_NAME"), - "key" = Sys.getenv("STORAGE_ACCOUNT_KEY"), - "endpointSuffix" = "core.windows.net" - ) - ), - "githubAuthenticationToken" = "", - "dockerAuthentication" = list("username" = "", - "password" = "", - "registry" = "") - ), + settings <- list( clusterConfig = list( "name" = poolName, "vmSize" = "Standard_D2_v2", @@ -46,4 +28,32 @@ getSettings <- function(dedicatedMin = 0, "commandLine" = list() ) ) + + if (file.exists('test_credentials.json')) { + doAzureParallel::setCredentials("test_credentials.json") + } + else{ + settings['credentials'] <- list( + "sharedKey" = list( + "batchAccount" = list( + "name" = Sys.getenv("BATCH_ACCOUNT_NAME"), + "key" = Sys.getenv("BATCH_ACCOUNT_KEY"), + "url" = Sys.getenv("BATCH_ACCOUNT_URL") + ), + "storageAccount" = list( + "name" = Sys.getenv("STORAGE_ACCOUNT_NAME"), + "key" = Sys.getenv("STORAGE_ACCOUNT_KEY"), + "endpointSuffix" = "core.windows.net" + ) + ), + "githubAuthenticationToken" = "", + "dockerAuthentication" = list("username" = "", + "password" = "", + "registry" = "") + ) + + doAzureParallel::setCredentials(settings$credentials) + } + + return(settings) }