-
Notifications
You must be signed in to change notification settings - Fork 4
Update to Swift 5.9 and raise deployment targets to macOS 13 / iOS 17 #10
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
Open
Sameh Sayed (sameh0)
wants to merge
4
commits into
main
Choose a base branch
from
update/swift-5.9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
059588e
Update to Swift 5.9 and raise deployment targets to macOS 13 / iOS 17…
sameh0 95ecf83
Use latest versions of official GitHub Actions
sameh0 b1420ed
Fix CI: select iOS/tvOS simulators dynamically instead of pinning dev…
sameh0 3daca76
Bump swift-docc-plugin dependency floor to 1.5.0 (latest)
sameh0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Tests/ManagedAppConfigLibTests/ManagedAppConfigTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| SPDX-License-Identifier: MIT | ||
| Copyright (c) 2017-2026 Jamf | ||
| */ | ||
|
|
||
| @testable import ManagedAppConfigLib | ||
| import XCTest | ||
|
|
||
| final class ManagedAppConfigTests: XCTestCase { | ||
| // `ManagedAppConfig` reads and writes `UserDefaults.standard` directly, so each test seeds and | ||
| // then clears the two well-known keys to avoid leaking state between tests. | ||
| private let configurationKey = ManagedAppConfig.configurationKey | ||
| private let feedbackKey = ManagedAppConfig.feedbackKey | ||
|
|
||
| override func tearDown() { | ||
| UserDefaults.standard.removeObject(forKey: configurationKey) | ||
| UserDefaults.standard.removeObject(forKey: feedbackKey) | ||
| super.tearDown() | ||
| } | ||
|
|
||
| // MARK: - Key constants | ||
|
|
||
| func testPublicKeyConstants() { | ||
| XCTAssertEqual(ManagedAppConfig.configurationKey, "com.apple.configuration.managed") | ||
| XCTAssertEqual(ManagedAppConfig.feedbackKey, "com.apple.feedback.managed") | ||
| } | ||
|
|
||
| func testSharedIsSingleton() { | ||
| XCTAssertTrue(ManagedAppConfig.shared === ManagedAppConfig.shared) | ||
| } | ||
|
|
||
| // MARK: - Configuration getter | ||
|
|
||
| func testGetConfigValueReturnsValueFromStandardDefaults() { | ||
| UserDefaults.standard.set(["deviceId": "abc123"], forKey: configurationKey) | ||
|
|
||
| let sut = ManagedAppConfig() | ||
|
|
||
| XCTAssertEqual(sut.getConfigValue(forKey: "deviceId") as? String, "abc123") | ||
| } | ||
|
|
||
| func testGetConfigValueReturnsNilForMissingKey() { | ||
| UserDefaults.standard.set(["deviceId": "abc123"], forKey: configurationKey) | ||
|
|
||
| let sut = ManagedAppConfig() | ||
|
|
||
| XCTAssertNil(sut.getConfigValue(forKey: "notThere")) | ||
| } | ||
|
|
||
| func testGetConfigValueReturnsNilWhenNoDictionary() { | ||
| let sut = ManagedAppConfig() | ||
|
|
||
| XCTAssertNil(sut.getConfigValue(forKey: "anything")) | ||
| } | ||
|
|
||
| // MARK: - Feedback getter / setter round-trip | ||
|
|
||
| func testUpdateValueCreatesFeedbackDictionaryWhenNoneExists() { | ||
| // Hits the branch where no feedback dictionary exists yet and a fresh one is created. | ||
| let sut = ManagedAppConfig() | ||
|
|
||
| sut.updateValue(42, forKey: "errorCount") | ||
|
|
||
| XCTAssertEqual(sut.getFeedbackValue(forKey: "errorCount") as? Int, 42) | ||
| } | ||
|
|
||
| func testUpdateValueMergesIntoExistingFeedbackDictionary() { | ||
| // Hits the branch where a feedback dictionary already exists and is updated in place. | ||
| let sut = ManagedAppConfig() | ||
|
|
||
| sut.updateValue(42, forKey: "errorCount") | ||
| sut.updateValue("running", forKey: "state") | ||
|
|
||
| XCTAssertEqual(sut.getFeedbackValue(forKey: "errorCount") as? Int, 42) | ||
| XCTAssertEqual(sut.getFeedbackValue(forKey: "state") as? String, "running") | ||
| } | ||
|
|
||
| func testUpdateValueOverwritesExistingValueForKey() { | ||
| let sut = ManagedAppConfig() | ||
|
|
||
| sut.updateValue(1, forKey: "errorCount") | ||
| sut.updateValue(2, forKey: "errorCount") | ||
|
|
||
| XCTAssertEqual(sut.getFeedbackValue(forKey: "errorCount") as? Int, 2) | ||
| } | ||
|
|
||
| func testGetFeedbackValueReturnsNilWhenNoDictionary() { | ||
| let sut = ManagedAppConfig() | ||
|
|
||
| XCTAssertNil(sut.getFeedbackValue(forKey: "errorCount")) | ||
| } | ||
|
|
||
| // MARK: - Change hooks | ||
|
|
||
| func testConfigChangedHookFiresWithConfigurationDictionary() { | ||
| let sut = ManagedAppConfig() | ||
| let expectation = expectation(description: "config hook called") | ||
| expectation.assertForOverFulfill = false | ||
|
|
||
| sut.addAppConfigChangedHook { config in | ||
| if config["title"] as? String == "hello" { | ||
| expectation.fulfill() | ||
| } | ||
| } | ||
|
|
||
| // Writing to standard defaults posts `UserDefaults.didChangeNotification`, which the | ||
| // observer set up in `ManagedAppConfig.init()` turns into a hook callback. | ||
| UserDefaults.standard.set(["title": "hello"], forKey: configurationKey) | ||
|
|
||
| wait(for: [expectation], timeout: 2.0) | ||
| } | ||
|
|
||
| func testFeedbackChangedHookFiresWithFeedbackDictionary() { | ||
| let sut = ManagedAppConfig() | ||
| let expectation = expectation(description: "feedback hook called") | ||
| expectation.assertForOverFulfill = false | ||
|
|
||
| sut.addAppFeedbackChangedHook { feedback in | ||
| if feedback["errorCount"] as? Int == 7 { | ||
| expectation.fulfill() | ||
| } | ||
| } | ||
|
|
||
| sut.updateValue(7, forKey: "errorCount") | ||
|
|
||
| wait(for: [expectation], timeout: 2.0) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.