SqlServer <- Sys.getenv("RTEST_SQL_SERVER")
if (SqlServer=='') SqlServer <- '.\\MRS'
cat("SqlServer='", SqlServer, "'\n", sep="")

# Note: for improved security, read connection string from a file, such as
# connectionString <- readLines("sqlConnString.txt")

rxTestArgs <- list(
    # Compute context specifications
	connectionString =  paste0("Driver={SQL Server};Server=",SqlServer,";Database=RevoTestDB;Trusted_Connection=true"),
    consoleOutput = FALSE,
    wait = TRUE,
    autoCleanup = TRUE,
    ### Additional args for tests
    rxTestOdbc = FALSE,
	rxHaveWritePermission = TRUE  # Set to FALSE to run only tests that read data
  )  

options(rxTestArgs = rxTestArgs)
rm(rxTestArgs)

# Run the tests
res <- RevoScaleR:::rxuRunTests( 
    testDir = system.file("IOQ", package = "MicrosoftML"),
    testFileRegexp = "SqlServerIOQ_Tests.R$")

if (inherits(res, "try-error") || (is.numeric(res) && (res > 0))) {
    quit(save='no', status = res)
}
	
# If a test fails due to a temporary problem (such as with the connection to the cluster), 
# rerun the single tests. As an example:
 
#RevoScaleR:::rxuRunTests( 
    #testDir = system.file("IOQ", package = "MicrosoftML"),
    #testFuncRegexp = "test.SqlServer.HPA.rxOneClassSvm", 
    #testFileRegexp = "SqlServerIOQ_Tests.R")
