connection = function(rw)
{
- if (rw == "r")
+ if (rw == "r" || rw == "rb")
{
- return(textConnection(self$read("text")))
+ REST <- private$collection$getRESTService()
+ return(REST$getConnection(private$collection$uuid,
+ self$getRelativePath(),
+ rw))
}
else if (rw == "w")
{
curl::handle_setopt(h, customrequest = "PROPFIND")
curl::handle_setheaders(h, .list = headers)
- propfindResponse <- curl::curl_fetch_memory(url, h)
+ propfindResponse <- curl::curl_fetch_memory(url, h)
},
MOVE = function(url, headers = NULL)
stop(paste("Server code:", serverResponse$status_code))
self$httpParser$parseResponse(serverResponse, "text")
+ },
+
+ getConnection = function(uuid, relativePath, openMode)
+ {
+ fileURL <- paste0(self$getWebDavHostName(),
+ "c=", uuid, "/", relativePath);
+ headers <- list(Authorization = paste("OAuth2", self$token))
+
+ h <- curl::new_handle()
+ curl::handle_setheaders(h, .list = headers)
+
+ conn <- curl::curl(url = fileURL, open = openMode, handle = h)
+
+ conn
}
),
getResourceSizeCallCount = NULL,
readCallCount = NULL,
writeCallCount = NULL,
+ getConnectionCallCount = NULL,
writeBuffer = NULL,
filtersAreConfiguredCorrectly = NULL,
bodyIsConfiguredCorrectly = NULL,
self$getResourceSizeCallCount <- 0
self$readCallCount <- 0
self$writeCallCount <- 0
+ self$getConnectionCallCount <- 0
self$filtersAreConfiguredCorrectly <- FALSE
self$bodyIsConfiguredCorrectly <- FALSE
self$writeBuffer <- content
self$writeCallCount <- self$writeCallCount + 1
self$returnContent
+ },
+
+ getConnection = function(relativePath, uuid, openMode)
+ {
+ self$getConnectionCallCount <- self$getConnectionCallCount + 1
+ self$returnContent
}
),
expect_that(fakeREST$readCallCount, equals(1))
})
-test_that(paste("connect returns textConnection opened",
- "in read mode when 'r' is passed as argument"), {
+test_that(paste("connection delegates connection creation ro RESTService class",
+ "which returns curl connection opened in read mode when",
+ "'r' of 'rb' is passed as argument"), {
collectionContent <- c("animal", "animal/fish")
- readContent <- "file content"
- fakeREST <- FakeRESTService$new(collectionContent, readContent)
+ fakeREST <- FakeRESTService$new(collectionContent)
api <- Arvados$new("myToken", "myHostName")
api$setRESTService(fakeREST)
connection <- fish$connection("r")
- expect_that(readLines(connection), equals("file content"))
+ expect_that(fakeREST$getConnectionCallCount, equals(1))
})
-test_that(paste("connect returns textConnection opened",
+test_that(paste("connection returns textConnection opened",
"in write mode when 'w' is passed as argument"), {
-
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)