Skip to content

Commit

Permalink
chore: kickoff release
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode authored Sep 5, 2023
2 parents 3fdd8cb + 73db7ad commit 360001e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ actor LogActor {
}

private func write(_ data: Data) throws {
try rotation.ensureFileExists()
if rotation.currentLogFile.hasSpace(for: data) {
try rotation.currentLogFile.write(data: data)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ final class LogRotation {
index: 0,
fileSizeLimitInBytes: fileSizeLimitInBytes)
}

func ensureFileExists() throws {
if !FileManager.default.fileExists(atPath: currentLogFile.fileURL.relativePath) {
try rotate()
}
}

/// - Returns: A UInt representing the best guess to which index to use
/// next when the number of log files is less that the limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,24 @@ final class LogActorTests: XCTestCase {
logs = try await systemUnderTest.getLogs()
XCTAssertEqual(logs.count, 2)
}

/// Given: a Log file
/// When: LogActor writes to a log file that doesn't exist
/// Then: the log file is created and the log entry is recorded
func testLogActorCreatesLogFileIfItDoesNotExist() async throws {
let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
let fileURL = try XCTUnwrap(files.first)
try FileManager.default.removeItem(at: fileURL)
var logs = try await systemUnderTest.getLogs()
XCTAssertEqual(logs.count, 0)

let entry = LogEntry(category: "LogActorTests", namespace: nil, level: .error, message: UUID().uuidString, created: .init(timeIntervalSince1970: 0))
try await systemUnderTest.record(entry)
try await systemUnderTest.synchronize()

logs = try await systemUnderTest.getLogs()
XCTAssertEqual(logs.count, 1)
let contents = try XCTUnwrap(FileManager.default.contents(atPath: fileURL.path))
XCTAssertNotNil(contents)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Amplify
import AWSPinpoint
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint
import UserNotifications
Expand Down Expand Up @@ -59,6 +60,13 @@ extension AWSPinpointPushNotificationsPlugin {
}
#endif

/// Retrieves the escape hatch to perform actions directly on PinpointClient.
///
/// - Returns: PinpointClientProtocol instance
public func getEscapeHatch() -> PinpointClientProtocol {
pinpoint.pinpointClient
}

private func recordNotification(_ userInfo: [String: Any],
applicationState: ApplicationState,
action: PushNotification.Action) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Amplify
import AWSPinpoint
@_spi(InternalAWSPinpoint) @testable import InternalAWSPinpoint
@testable import AWSPinpointPushNotificationsPlugin
import UserNotifications
Expand Down Expand Up @@ -206,6 +207,19 @@ class AWSPinpointPushNotificationsPluginClientBehaviourTests: AWSPinpointPushNot
}
#endif

// - MARK: Escape Hatch tests
/// Given: A configured AWSPinpointPushNotificationsPlugin instance
/// When: The getEscapeHatch API is invoked
/// Then: The underlying PinpointClientProtocol instance is retrieved
func testGetEscapeHatch_shouldReturnPinpointClient() {
guard let escapeHatch = plugin.getEscapeHatch() as? PinpointClient else {
XCTFail("Unable to retrieve PinpointClient")
return
}

XCTAssertTrue(escapeHatch === (mockPinpoint.pinpointClient as? PinpointClient))
}

private func createUserInfo(for source: PushNotification.Source) -> Notifications.Push.UserInfo {
return [
"data": [
Expand Down

0 comments on commit 360001e

Please sign in to comment.