Skip to content

Commit

Permalink
test2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaland committed Sep 7, 2024
1 parent 546464e commit 617dad5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase {
let task = Amplify.Storage.uploadData(key: key,
data: data,
options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint]))
_ = try await task.value
try await Amplify.Storage.remove(key: key)
await waitTasks(timeout: 5) {
_ = try await task.value
try await Amplify.Storage.remove(key: key)
}
}

/// Given: A data object.
Expand All @@ -35,15 +37,17 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase {
func testUploadDataWithAccelerateDisabledExplicitlyToWrongType() async throws {
let key = UUID().uuidString
let data = Data(key.utf8)
do {
let task = Amplify.Storage.uploadData(key: key,
data: data,
options: .init(pluginOptions:["useAccelerateEndpoint": "false"]))
_ = try await task.value
XCTFail("Expecting error from bogus useAccelerateEndpoint value type (String)")
try await Amplify.Storage.remove(key: key)
} catch {
XCTAssertNotNil(error)
await waitTasks(timeout: 5) {
do {
let task = Amplify.Storage.uploadData(key: key,
data: data,
options: .init(pluginOptions:["useAccelerateEndpoint": "false"]))
_ = try await task.value
XCTFail("Expecting error from bogus useAccelerateEndpoint value type (String)")
try await Amplify.Storage.remove(key: key)
} catch {
XCTAssertNotNil(error)
}
}
}

Expand All @@ -63,8 +67,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase {
let task = Amplify.Storage.uploadFile(key: key,
local: fileURL,
options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint]))
_ = try await task.value
try await Amplify.Storage.remove(key: key)
await waitTasks(timeout: 5) {
_ = try await task.value
try await Amplify.Storage.remove(key: key)
}
}

/// Given: A large data object.
Expand All @@ -75,8 +81,10 @@ class AWSS3StoragePluginAccelerateIntegrationTests: AWSS3StoragePluginTestBase {
let task = Amplify.Storage.uploadData(key: key,
data: AWSS3StoragePluginTestBase.largeDataObject,
options: .init(pluginOptions:["useAccelerateEndpoint": useAccelerateEndpoint]))
_ = try await task.value
try await Amplify.Storage.remove(key: key)
await waitTasks(timeout: 15) {
_ = try await task.value
try await Amplify.Storage.remove(key: key)
}
}

/// Given: An object in storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase {
let fileURL = URL(fileURLWithPath: filePath)
removeIfExists(fileURL)

_ = try await Amplify.Storage.downloadFile(key: key, local: fileURL, options: .init()).value
await waitTasks(timeout: 20) {
_ = try await Amplify.Storage.downloadFile(key: key, local: fileURL, options: .init()).value
}

let fileExists = FileManager.default.fileExists(atPath: fileURL.path)
XCTAssertTrue(fileExists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase
let data = Data(key.utf8)
let uniqueStringPath = "public/\(key)"

_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value
}

let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath))

Expand Down Expand Up @@ -56,13 +58,15 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase
// Sign in
_ = try await Amplify.Auth.signIn(username: Self.user1, password: Self.password)

_ = try await Amplify.Storage.uploadData(
path: .fromIdentityID({ identityId in
uniqueStringPath = "protected/\(identityId)/\(key)"
return uniqueStringPath + "test1"
}),
data: data,
options: nil).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(
path: .fromIdentityID({ identityId in
uniqueStringPath = "protected/\(identityId)/\(key)"
return uniqueStringPath + "test1"
}),
data: data,
options: nil).value
}

let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath))

Expand Down Expand Up @@ -101,13 +105,15 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase
// Sign in
_ = try await Amplify.Auth.signIn(username: Self.user1, password: Self.password)

_ = try await Amplify.Storage.uploadData(
path: .fromIdentityID({ identityId in
uniqueStringPath = "private/\(identityId)/\(key)"
return uniqueStringPath + "test1"
}),
data: data,
options: nil).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(
path: .fromIdentityID({ identityId in
uniqueStringPath = "private/\(identityId)/\(key)"
return uniqueStringPath + "test1"
}),
data: data,
options: nil).value
}

let firstListResult = try await Amplify.Storage.list(path: .fromString(uniqueStringPath))

Expand Down Expand Up @@ -198,10 +204,12 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase
let uniqueStringPath = "public/\(path)"

// Upload data
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test2"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath1/test"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath2/test"), data: data, options: nil).value
await waitTasks(timeout: 15) {
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test1"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/test2"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath1/test"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "/subpath2/test"), data: data, options: nil).value
}

let result = try await Amplify.Storage.list(
path: .fromString("\(uniqueStringPath)/"),
Expand Down Expand Up @@ -232,8 +240,10 @@ class AWSS3StoragePluginListObjectsIntegrationTests: AWSS3StoragePluginTestBase
let uniqueStringPath = "public/\(path)"

// Upload data
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-test"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-subpath-test"), data: data, options: nil).value
await waitTasks(timeout: 10) {
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-test"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-subpath-test"), data: data, options: nil).value
}

let result = try await Amplify.Storage.list(
path: .fromString("\(uniqueStringPath)-"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {
let key = UUID().uuidString
let data = Data(key.utf8)

_ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
}

// Only the remove operation results in an SDK request
XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method } , [.delete])
Expand All @@ -80,8 +82,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {
func testUploadEmptyData() async throws {
let key = UUID().uuidString
let data = Data("".utf8)
_ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
}

XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"])
try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests)
Expand All @@ -96,9 +100,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {

let fileURL = URL(fileURLWithPath: filePath)
FileManager.default.createFile(atPath: filePath, contents: Data(key.utf8), attributes: nil)

_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
}

// Only the remove operation results in an SDK request
XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method} , [.delete])
Expand All @@ -117,8 +122,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {
let fileURL = URL(fileURLWithPath: filePath)
FileManager.default.createFile(atPath: filePath, contents: Data("".utf8), attributes: nil)

_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
}

XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"])
try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests)
Expand All @@ -130,12 +137,14 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {
func testUploadLargeData() async throws {
let key = "public/" + UUID().uuidString

let uploadKey = try await Amplify.Storage.uploadData(path: .fromString(key),
data: AWSS3StoragePluginTestBase.largeDataObject,
options: nil).value
XCTAssertEqual(uploadKey, key)
await waitTasks(timeout: 20) {
let uploadKey = try await Amplify.Storage.uploadData(path: .fromString(key),
data: AWSS3StoragePluginTestBase.largeDataObject,
options: nil).value
XCTAssertEqual(uploadKey, key)

try await Amplify.Storage.remove(path: .fromString(key))
try await Amplify.Storage.remove(path: .fromString(key))
}

let userAgents = requestRecorder.urlRequests.compactMap { $0.allHTTPHeaderFields?["User-Agent"] }
XCTAssertGreaterThan(userAgents.count, 1)
Expand All @@ -157,8 +166,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase {
contents: AWSS3StoragePluginTestBase.largeDataObject,
attributes: nil)

_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
await waitTasks(timeout: 20) {
_ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value
_ = try await Amplify.Storage.remove(path: .fromString("public/\(key)"))
}

let userAgents = requestRecorder.urlRequests.compactMap { $0.allHTTPHeaderFields?["User-Agent"] }
XCTAssertGreaterThan(userAgents.count, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase {
// upload file
let key = UUID().uuidString
let fileURL = temporaryFile(named: key, data: data(mb: 1))
_ = try await Amplify.Storage.uploadFile(
key: key,
local: fileURL,
options: options
).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadFile(
key: key,
local: fileURL,
options: options
).value
}

// call `HeadObject` through SDK escape hatch
let head = try await headObject(key: "public/\(key)")
Expand Down Expand Up @@ -65,11 +67,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase {
// upload file
let key = UUID().uuidString
let fileURL = temporaryFile(named: key, data: data(mb: 7))
_ = try await Amplify.Storage.uploadFile(
key: key,
local: fileURL,
options: options
).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadFile(
key: key,
local: fileURL,
options: options
).value
}

// call `HeadObject` through SDK escape hatch
let head = try await headObject(key: "public/\(key)")
Expand Down Expand Up @@ -102,11 +106,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase {

// upload file
let key = UUID().uuidString
_ = try await Amplify.Storage.uploadData(
key: key,
data: data(mb: 1),
options: options
).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(
key: key,
data: self.data(mb: 1),
options: options
).value
}

// call `HeadObject` through SDK escape hatch
let head = try await headObject(key: "public/\(key)")
Expand Down Expand Up @@ -139,11 +145,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase {

// upload file
let key = UUID().uuidString
_ = try await Amplify.Storage.uploadData(
key: key,
data: data(mb: 7),
options: options
).value
await waitTasks(timeout: 5) {
_ = try await Amplify.Storage.uploadData(
key: key,
data: self.data(mb: 7),
options: options
).value
}

// call `HeadObject` through SDK escape hatch
let head = try await headObject(key: "public/\(key)")
Expand Down Expand Up @@ -187,11 +195,13 @@ class AWSS3StoragePluginUploadMetadataTestCase: AWSS3StoragePluginTestBase {

// upload file
let key = UUID().uuidString
_ = try await Amplify.Storage.uploadData(
key: key,
data: data(mb: 1),
options: options
).value
await waitTasks(timeout: 10) {
_ = try await Amplify.Storage.uploadData(
key: key,
data: self.data(mb: 1),
options: options
).value
}

// call `HeadObject` through SDK escape hatch
let head = try await headObject(key: "public/\(key)")
Expand Down

0 comments on commit 617dad5

Please sign in to comment.