Skip to content

Commit 360001e

Browse files
authored
chore: kickoff release
2 parents 3fdd8cb + 73db7ad commit 360001e

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogActor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ actor LogActor {
2929
}
3030

3131
private func write(_ data: Data) throws {
32+
try rotation.ensureFileExists()
3233
if rotation.currentLogFile.hasSpace(for: data) {
3334
try rotation.currentLogFile.write(data: data)
3435
} else {

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ final class LogRotation {
9898
index: 0,
9999
fileSizeLimitInBytes: fileSizeLimitInBytes)
100100
}
101+
102+
func ensureFileExists() throws {
103+
if !FileManager.default.fileExists(atPath: currentLogFile.fileURL.relativePath) {
104+
try rotate()
105+
}
106+
}
101107

102108
/// - Returns: A UInt representing the best guess to which index to use
103109
/// next when the number of log files is less that the limit

AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginTests/LogActorTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,24 @@ final class LogActorTests: XCTestCase {
127127
logs = try await systemUnderTest.getLogs()
128128
XCTAssertEqual(logs.count, 2)
129129
}
130+
131+
/// Given: a Log file
132+
/// When: LogActor writes to a log file that doesn't exist
133+
/// Then: the log file is created and the log entry is recorded
134+
func testLogActorCreatesLogFileIfItDoesNotExist() async throws {
135+
let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
136+
let fileURL = try XCTUnwrap(files.first)
137+
try FileManager.default.removeItem(at: fileURL)
138+
var logs = try await systemUnderTest.getLogs()
139+
XCTAssertEqual(logs.count, 0)
140+
141+
let entry = LogEntry(category: "LogActorTests", namespace: nil, level: .error, message: UUID().uuidString, created: .init(timeIntervalSince1970: 0))
142+
try await systemUnderTest.record(entry)
143+
try await systemUnderTest.synchronize()
144+
145+
logs = try await systemUnderTest.getLogs()
146+
XCTAssertEqual(logs.count, 1)
147+
let contents = try XCTUnwrap(FileManager.default.contents(atPath: fileURL.path))
148+
XCTAssertNotNil(contents)
149+
}
130150
}

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import Amplify
9+
import AWSPinpoint
910
import Foundation
1011
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint
1112
import UserNotifications
@@ -59,6 +60,13 @@ extension AWSPinpointPushNotificationsPlugin {
5960
}
6061
#endif
6162

63+
/// Retrieves the escape hatch to perform actions directly on PinpointClient.
64+
///
65+
/// - Returns: PinpointClientProtocol instance
66+
public func getEscapeHatch() -> PinpointClientProtocol {
67+
pinpoint.pinpointClient
68+
}
69+
6270
private func recordNotification(_ userInfo: [String: Any],
6371
applicationState: ApplicationState,
6472
action: PushNotification.Action) async {

AmplifyPlugins/Notifications/Push/Tests/AWSPinpointPushNotificationsPluginUnitTests/AWSPinpointPushNotificationsPluginClientBehaviourTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import Amplify
9+
import AWSPinpoint
910
@_spi(InternalAWSPinpoint) @testable import InternalAWSPinpoint
1011
@testable import AWSPinpointPushNotificationsPlugin
1112
import UserNotifications
@@ -206,6 +207,19 @@ class AWSPinpointPushNotificationsPluginClientBehaviourTests: AWSPinpointPushNot
206207
}
207208
#endif
208209

210+
// - MARK: Escape Hatch tests
211+
/// Given: A configured AWSPinpointPushNotificationsPlugin instance
212+
/// When: The getEscapeHatch API is invoked
213+
/// Then: The underlying PinpointClientProtocol instance is retrieved
214+
func testGetEscapeHatch_shouldReturnPinpointClient() {
215+
guard let escapeHatch = plugin.getEscapeHatch() as? PinpointClient else {
216+
XCTFail("Unable to retrieve PinpointClient")
217+
return
218+
}
219+
220+
XCTAssertTrue(escapeHatch === (mockPinpoint.pinpointClient as? PinpointClient))
221+
}
222+
209223
private func createUserInfo(for source: PushNotification.Source) -> Notifications.Push.UserInfo {
210224
return [
211225
"data": [

0 commit comments

Comments
 (0)