Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: kickoff release #3207

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading