-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8de4b78
commit 29890f7
Showing
3 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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,137 @@ | ||
import Confidence | ||
import XCTest | ||
|
||
final class ConfidenceTests: XCTestCase { | ||
func testWithContext() { | ||
let confidenceParent = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: ["k1": ConfidenceValue(string: "v1")] | ||
) | ||
let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( | ||
["k2": ConfidenceValue(string: "v2")] | ||
) | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v2") | ||
] | ||
XCTAssertEqual(confidenceChild.context, expected) | ||
} | ||
|
||
func testWithContextUpdateParent() { | ||
let confidenceParent = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: ["k1": ConfidenceValue(string: "v1")] | ||
) | ||
let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( | ||
["k2": ConfidenceValue(string: "v2")] | ||
) | ||
confidenceParent.updateContextEntry( | ||
key: "k3", | ||
value: ConfidenceValue(string: "v3")) | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v2"), | ||
"k3": ConfidenceValue(string: "v3"), | ||
] | ||
XCTAssertEqual(confidenceChild.context, expected) | ||
} | ||
|
||
func testUpdateContextWithOverride() { | ||
let confidence = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: ["k1": ConfidenceValue(string: "v1")] | ||
) | ||
confidence.updateContextEntry( | ||
key: "k1", | ||
value: ConfidenceValue(string: "v3")) | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v3"), | ||
] | ||
XCTAssertEqual(confidence.context, expected) | ||
} | ||
|
||
func testWithContextUpdateParentWithoutOverride() { | ||
let confidenceParent = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: ["k1": ConfidenceValue(string: "v1")] | ||
) | ||
let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( | ||
["k2": ConfidenceValue(string: "v2")] | ||
) | ||
confidenceParent.updateContextEntry( | ||
key: "k2", | ||
value: ConfidenceValue(string: "v4")) | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v2"), | ||
] | ||
XCTAssertEqual(confidenceChild.context, expected) | ||
} | ||
|
||
func testWithContextUpdateChildWithOverride() { | ||
let confidenceParent = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: ["k1": ConfidenceValue(string: "v1")] | ||
) | ||
let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( | ||
["k2": ConfidenceValue(string: "v2")] | ||
) | ||
confidenceChild.updateContextEntry( | ||
key: "k2", | ||
value: ConfidenceValue(string: "v4")) | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v4"), | ||
] | ||
XCTAssertEqual(confidenceChild.context, expected) | ||
} | ||
|
||
func testRemoveContextEntry() { | ||
let confidence = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v2") | ||
] | ||
) | ||
confidence.removeContextEntry(key: "k2") | ||
let expected = [ | ||
"k1": ConfidenceValue(string: "v1") | ||
] | ||
XCTAssertEqual(confidence.context, expected) | ||
} | ||
|
||
func testClearContext() { | ||
let confidence = Confidence.init( | ||
clientSecret: "", | ||
timeout: TimeInterval(), | ||
region: .europe, | ||
initializationStrategy: .activateAndFetchAsync, | ||
context: [ | ||
"k1": ConfidenceValue(string: "v1"), | ||
"k2": ConfidenceValue(string: "v2") | ||
] | ||
) | ||
confidence.clearContext() | ||
let expected: ConfidenceStruct = [:] | ||
XCTAssertEqual(confidence.context, expected) | ||
} | ||
} |