Created S3StorageTests.testFetch test case

This commit is contained in:
Caleb Kleveter 2018-12-14 08:30:06 -06:00
parent cc2d95c0cf
commit e325f435ee
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
2 changed files with 19 additions and 5 deletions

View File

@ -34,19 +34,23 @@ public struct S3Storage: Storage, ServiceType {
do {
let client = try self.container.make(S3StorageClient.self)
guard let path = path ?? self.defaultPath else {
throw StorageError(identifier: "pathRequired", reason: "No path received for the file being uploaded")
let s3Path: String
if let unwrappedPath = path {
s3Path = unwrappedPath + "/" + file.filename
} else if let unwrappedPath = self.defaultPath {
s3Path = unwrappedPath + "/" + file.filename
} else {
s3Path = file.filename
}
let type = file.contentType?.description ?? MediaType.plainText.description
let upload = File.Upload(
data: file.data,
destination: path,
destination: s3Path,
mime: type
)
return try client.put(file: upload, on: container).map { response in
print(response.path)
return try client.urlBuilder(for: self.container).url(file: response.path).description
}
} catch let error {

View File

@ -67,7 +67,17 @@ final class S3StorageTests: XCTestCase {
XCTAssertEqual(path, "https://s3.us-east-1.amazonaws.com/ck-s3storage-test/markdown/test.md")
}
func testFetch()throws {
let storage = try self.app.make(S3Storage.self)
let file = try storage.fetch(file: "markdown/test.md").wait()
XCTAssertEqual(file.filename, "test.md")
XCTAssertEqual(file.data, self.data)
}
static var allTests: [(String, (S3StorageTests) -> ()throws -> ())] = [
("testStore", testStore)
("testStore", testStore),
("testFetch", testFetch)
]
}