Skip to content

Commit

Permalink
More test fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayterDev committed Sep 3, 2024
1 parent 636d565 commit 998fb7a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
appearancePreferences: .shared,
pinnedTabsManager: pinnedTabsManager,
internalUserDecider: internalUserDecider,
configurationStore: ConfigurationStore.shared,
configurationStore: ConfigurationStore(),
remoteMessagingAvailabilityProvider: PrivacyConfigurationRemoteMessagingAvailabilityProvider(
privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager
)
Expand Down
18 changes: 9 additions & 9 deletions DuckDuckGo/Configuration/ConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class ConfigurationManager: DefaultConfigurationManager {
await updateBloomFilterTask.value
await updateBloomFilterExclusionsTask.value

ConfigurationStore.shared.log()
(store as? ConfigurationStore)?.log()

Logger.config.info("last update \(String(describing: self.lastUpdateTime), privacy: .public)")
Logger.config.info("last refresh check \(String(describing: self.lastRefreshCheckTime), privacy: .public)")
Expand Down Expand Up @@ -141,18 +141,18 @@ final class ConfigurationManager: DefaultConfigurationManager {

private func updateTrackerBlockingDependencies() {
lastConfigurationInstallDate = Date()
ContentBlocking.shared.trackerDataManager.reload(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet),
data: ConfigurationStore.shared.loadData(for: .trackerDataSet))
ContentBlocking.shared.privacyConfigurationManager.reload(etag: ConfigurationStore.shared.loadEtag(for: .privacyConfiguration),
data: ConfigurationStore.shared.loadData(for: .privacyConfiguration))
ContentBlocking.shared.trackerDataManager.reload(etag: store.loadEtag(for: .trackerDataSet),
data: store.loadData(for: .trackerDataSet))
ContentBlocking.shared.privacyConfigurationManager.reload(etag: store.loadEtag(for: .privacyConfiguration),
data: store.loadData(for: .privacyConfiguration))
ContentBlocking.shared.contentBlockingManager.scheduleCompilation()
}

private func updateBloomFilter() async throws {
guard let specData = ConfigurationStore.shared.loadData(for: .bloomFilterSpec) else {
guard let specData = store.loadData(for: .bloomFilterSpec) else {
throw Error.bloomFilterSpecNotFound
}
guard let bloomFilterData = ConfigurationStore.shared.loadData(for: .bloomFilterBinary) else {
guard let bloomFilterData = store.loadData(for: .bloomFilterBinary) else {
throw Error.bloomFilterBinaryNotFound
}
try await Task.detached {
Expand All @@ -168,7 +168,7 @@ final class ConfigurationManager: DefaultConfigurationManager {
}

private func updateBloomFilterExclusions() async throws {
guard let bloomFilterExclusions = ConfigurationStore.shared.loadData(for: .bloomFilterExcludedDomains) else {
guard let bloomFilterExclusions = store.loadData(for: .bloomFilterExcludedDomains) else {
throw Error.bloomFilterExclusionsNotFound
}
try await Task.detached {
Expand All @@ -186,7 +186,7 @@ final class ConfigurationManager: DefaultConfigurationManager {

extension ConfigurationManager {
override var presentedItemURL: URL? {
ConfigurationStore.shared.fileUrl(for: .privacyConfiguration)
store.fileUrl(for: .privacyConfiguration)
}

override func presentedItemDidChange() {
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/Configuration/ConfigurationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ final class ConfigurationStore: ConfigurationStoring {
static let configStorageRemoteMessagingConfigEtag = "config.storage.remotemessagingconfig.etag"
}

static let shared = ConfigurationStore()
private let defaults: KeyValueStoring

private var trackerRadarEtag: String? {
Expand Down
6 changes: 3 additions & 3 deletions DuckDuckGo/ContentBlocker/ContentBlocking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ final class AppContentBlocking {
// keeping whole ContentBlocking state initialization in one place to avoid races between updates publishing and rules storing
@MainActor
init(internalUserDecider: InternalUserDecider) {
let configStorage = ConfigurationStore.shared
let configStorage = ConfigurationStore()
privacyConfigurationManager = PrivacyConfigurationManager(fetchedETag: configStorage.loadEtag(for: .privacyConfiguration),
fetchedData: configStorage.loadData(for: .privacyConfiguration),
embeddedDataProvider: AppPrivacyConfigurationDataProvider(),
localProtection: LocalUnprotectedDomains.shared,
errorReporting: Self.debugEvents,
internalUserDecider: internalUserDecider)

trackerDataManager = TrackerDataManager(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet),
data: ConfigurationStore.shared.loadData(for: .trackerDataSet),
trackerDataManager = TrackerDataManager(etag: configStorage.loadEtag(for: .trackerDataSet),
data: configStorage.loadData(for: .trackerDataSet),
embeddedDataProvider: AppTrackerDataSetProvider(),
errorReporting: Self.debugEvents)

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/ContentBlocker/Mocks/ContentBlockingMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ final class ContentBlockingMock: NSObject, ContentBlockingProtocol, AdClickAttri
var embeddedDataEtag: String = ""
var embeddedData: Data = .init()
}
var trackerDataManager = TrackerDataManager(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet),
data: ConfigurationStore.shared.loadData(for: .trackerDataSet),
var trackerDataManager = TrackerDataManager(etag: ConfigurationStore().loadEtag(for: .trackerDataSet),
data: ConfigurationStore().loadData(for: .trackerDataSet),
embeddedDataProvider: AppTrackerDataSetProvider(),
errorReporting: nil)

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protocol ScriptSourceProviding {
// refactor: ScriptSourceProvider to be passed to init methods as `some ScriptSourceProviding`, DefaultScriptSourceProvider to be killed
// swiftlint:disable:next identifier_name
@MainActor func DefaultScriptSourceProvider() -> ScriptSourceProviding {
ScriptSourceProvider(configStorage: ConfigurationStore.shared, privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager, webTrackingProtectionPreferences: WebTrackingProtectionPreferences.shared, contentBlockingManager: ContentBlocking.shared.contentBlockingManager, trackerDataManager: ContentBlocking.shared.trackerDataManager, tld: ContentBlocking.shared.tld)
ScriptSourceProvider(configStorage: ConfigurationStore(), privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager, webTrackingProtectionPreferences: WebTrackingProtectionPreferences.shared, contentBlockingManager: ContentBlocking.shared.contentBlockingManager, trackerDataManager: ContentBlocking.shared.trackerDataManager, tld: ContentBlocking.shared.tld)
}

struct ScriptSourceProvider: ScriptSourceProviding {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/RemoteMessaging/RemoteMessagingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
urlSession: .session(),
eventMapping: ConfigurationManager.configurationDebugEvents
),
configurationStore: ConfigurationStore.shared
configurationStore: ConfigurationStore()
)
self.configMatcherProvider = configMatcherProvider
self.remoteMessagingAvailabilityProvider = remoteMessagingAvailabilityProvider
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/Autoconsent/AutoconsentMessageProtocolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class AutoconsentMessageProtocolTests: XCTestCase {
privacyConfigurationManager: MockPrivacyConfigurationManager(),
webTrackingProtectionPreferences: WebTrackingProtectionPreferences.shared, // mock
contentBlockingManager: ContentBlockerRulesManagerMock(),
trackerDataManager: TrackerDataManager(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet),
data: ConfigurationStore.shared.loadData(for: .trackerDataSet),
trackerDataManager: TrackerDataManager(etag: ConfigurationStore().loadEtag(for: .trackerDataSet),
data: ConfigurationStore().loadData(for: .trackerDataSet),
embeddedDataProvider: AppTrackerDataSetProvider(),
errorReporting: nil),
tld: TLD()),
Expand Down
12 changes: 7 additions & 5 deletions UnitTests/Configuration/ConfigurationStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ import Configuration

final class ConfigurationStorageTests: XCTestCase {

var configurationStore: ConfigurationStore = ConfigurationStore()

override func tearDown() {
super.tearDown()
for config in Configuration.allCases {
let url = ConfigurationStore.shared.fileUrl(for: config)
let url = configurationStore.fileUrl(for: config)
try? FileManager.default.removeItem(at: url)
}
}

func test_when_data_is_saved_for_config_then_it_can_be_loaded_correctly() {
for config in Configuration.allCases {
let uuid = UUID().uuidString
try? ConfigurationStore.shared.saveData(uuid.data(using: .utf8)!, for: config)
XCTAssertEqual(uuid, ConfigurationStore.shared.loadData(for: config)?.utf8String())
try? configurationStore.saveData(uuid.data(using: .utf8)!, for: config)
XCTAssertEqual(uuid, configurationStore.loadData(for: config)?.utf8String())
}
}

func test_when_etag_is_saved_for_config_then_it_can_be_loaded_correctly() {
for config in Configuration.allCases {
let etag = UUID().uuidString
try? ConfigurationStore.shared.saveEtag(etag, for: config)
XCTAssertEqual(etag, ConfigurationStore.shared.loadEtag(for: config))
try? configurationStore.saveEtag(etag, for: config)
XCTAssertEqual(etag, configurationStore.loadEtag(for: config))
}
}

Expand Down
9 changes: 5 additions & 4 deletions UnitTests/ContentBlocker/ContentBlockingUpdatingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ final class ContentBlockingUpdatingTests: XCTestCase {

@MainActor
override func setUp() {
let configStore = ConfigurationStore()
updating = UserContentUpdating(contentBlockerRulesManager: rulesManager,
privacyConfigurationManager: MockPrivacyConfigurationManager(),
trackerDataManager: TrackerDataManager(etag: ConfigurationStore.shared.loadEtag(for: .trackerDataSet),
data: ConfigurationStore.shared.loadData(for: .trackerDataSet),
embeddedDataProvider: AppTrackerDataSetProvider(),
errorReporting: nil),
trackerDataManager: TrackerDataManager(etag: configStore.loadEtag(for: .trackerDataSet),
data: configStore.loadData(for: .trackerDataSet),
embeddedDataProvider: AppTrackerDataSetProvider(),
errorReporting: nil),
configStorage: MockConfigurationStore(),
webTrackingProtectionPreferences: preferences,
tld: TLD())
Expand Down

0 comments on commit 998fb7a

Please sign in to comment.