Skip to content

Commit

Permalink
Rework MockEventLoggingDataSource to be immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Mar 27, 2020
1 parent 8cc85d7 commit 8723261
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions Automattic-Tracks-iOSTests/Test Helpers/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@ enum MockError: Error {
}

class MockEventLoggingDataSource: EventLoggingDataSource {

var loggingEncryptionKey: String = "foo"
var previousSessionLogPath: URL? = nil

/// Overrides for logUploadURL
var _logUploadURL: URL = URL(string: "example.com")!

private let _loggingEncryptionKey: String
private let _logUploadURL: URL

required init (loggingEncryptionKey: String, logUploadURL: URL) {
_loggingEncryptionKey = loggingEncryptionKey
_logUploadURL = logUploadURL
}

var loggingEncryptionKey: String {
return _loggingEncryptionKey
}

var logUploadURL: URL {
return _logUploadURL
}

func setLogUploadUrl(_ url: URL) {
self._logUploadURL = url
var previousSessionLogPath: URL? {
return nil
}

func withEncryptionKeys() -> Self {
static func withEncryptionKeys() -> Self {
let keyPair = Sodium().box.keyPair()!
loggingEncryptionKey = Data(keyPair.publicKey).base64EncodedString()
return self
let encryptionKey = Data(keyPair.publicKey).base64EncodedString()
return Self(loggingEncryptionKey: encryptionKey, logUploadURL: URL(string: "example.com")!)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EventLoggingUploadManagerTests: XCTestCase {
super.setUp()

delegate = MockEventLoggingDelegate()
dataSource = MockEventLoggingDataSource()
dataSource = MockEventLoggingDataSource.withEncryptionKeys()
networkService = MockEventLoggingNetworkService()

uploadManager = EventLoggingUploadManager(
Expand Down

0 comments on commit 8723261

Please sign in to comment.