-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecation workarounds in swift test code
- Loading branch information
1 parent
ace8109
commit bd9301e
Showing
9 changed files
with
101 additions
and
26 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
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 |
---|---|---|
|
@@ -6,7 +6,8 @@ class SentryEnvelopeTests: XCTestCase { | |
|
||
private class Fixture { | ||
let sdkVersion = "sdkVersion" | ||
let userFeedback: UserFeedback | ||
@available(*, deprecated, message: "SentryUserFeedback is deprecated in favor of SentryFeedback.") | ||
let userFeedback: UserFeedback = TestData.userFeedback | ||
let path = "test.log" | ||
let data = "hello".data(using: .utf8) | ||
|
||
|
@@ -15,11 +16,6 @@ class SentryEnvelopeTests: XCTestCase { | |
let dataTooBig: Data | ||
|
||
init() { | ||
userFeedback = UserFeedback(eventId: SentryId()) | ||
userFeedback.comments = "It doesn't work!" | ||
userFeedback.email = "[email protected]" | ||
userFeedback.name = "John Me" | ||
|
||
dataAllowed = Data([UInt8](repeating: 1, count: Int(maxAttachmentSize))) | ||
dataTooBig = Data([UInt8](repeating: 1, count: Int(maxAttachmentSize) + 1)) | ||
} | ||
|
@@ -49,7 +45,7 @@ class SentryEnvelopeTests: XCTestCase { | |
return event | ||
} | ||
} | ||
|
||
private let fixture = Fixture() | ||
|
||
override func setUp() { | ||
|
@@ -206,6 +202,7 @@ class SentryEnvelopeTests: XCTestCase { | |
} | ||
} | ||
|
||
@available(*, deprecated, message: "SentryUserFeedback is deprecated in favor of SentryFeedback. This test case can be removed when SentryUserFeedback is removed.") | ||
func testInitWithUserFeedback() throws { | ||
let userFeedback = fixture.userFeedback | ||
|
||
|
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 |
---|---|---|
|
@@ -302,6 +302,7 @@ class TestData { | |
return scope | ||
} | ||
|
||
@available(*, deprecated, message: "SentryUserFeedback is deprecated in favor of SentryFeedback.") | ||
static var userFeedback: UserFeedback { | ||
let userFeedback = UserFeedback(eventId: SentryId()) | ||
userFeedback.comments = "It doesn't really" | ||
|
@@ -310,6 +311,8 @@ class TestData { | |
return userFeedback | ||
} | ||
|
||
static var feedback = SentryFeedback(message: "It doesn't really", name: "John Me", email: "[email protected]", associatedEventId: SentryId()) | ||
|
||
static func setContext(_ scope: Scope) { | ||
scope.setContext(value: TestData.context["context"]!, key: "context") | ||
} | ||
|
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 |
---|---|---|
|
@@ -39,6 +39,8 @@ class SentryClientTest: XCTestCase { | |
let queue = DispatchQueue(label: "SentryHubTests", qos: .utility, attributes: [.concurrent]) | ||
let dispatchQueue = TestSentryDispatchQueueWrapper() | ||
|
||
let feedback = SentryFeedback(message: "A test message", name: "Abe Tester", email: "[email protected]", source: .custom, associatedEventId: SentryId()) | ||
|
||
init() throws { | ||
session = SentrySession(releaseName: "release", distinctId: "some-id") | ||
session.incrementErrors() | ||
|
@@ -1166,35 +1168,40 @@ class SentryClientTest: XCTestCase { | |
let serializedSpans = try XCTUnwrap(serialized["spans"] as? [[String: Any]]) | ||
XCTAssertEqual(1, serializedSpans.count) | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_MessageNotSent() { | ||
let sut = fixture.getSutWithNoDsn() | ||
let eventId = sut.capture(message: fixture.messageAsString) | ||
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testDisabled_MessageNotSent() { | ||
let sut = fixture.getSutDisabledSdk() | ||
let eventId = sut.capture(message: fixture.messageAsString) | ||
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_ExceptionNotSent() { | ||
let sut = fixture.getSutWithNoDsn() | ||
let eventId = sut.capture(exception: exception) | ||
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_ErrorNotSent() { | ||
let sut = fixture.getSutWithNoDsn() | ||
let eventId = sut.capture(error: error) | ||
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_SessionsNotSent() { | ||
_ = SentryEnvelope(event: Event()) | ||
fixture.getSut(configureOptions: { options in | ||
|
@@ -1203,7 +1210,8 @@ class SentryClientTest: XCTestCase { | |
|
||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_EventWithSessionsNotSent() { | ||
_ = SentryEnvelope(event: Event()) | ||
let eventId = fixture.getSut(configureOptions: { options in | ||
|
@@ -1213,7 +1221,8 @@ class SentryClientTest: XCTestCase { | |
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_ExceptionWithSessionsNotSent() { | ||
_ = SentryEnvelope(event: Event()) | ||
let eventId = fixture.getSut(configureOptions: { options in | ||
|
@@ -1225,7 +1234,8 @@ class SentryClientTest: XCTestCase { | |
eventId.assertIsEmpty() | ||
assertNothingSent() | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testNoDsn_ErrorWithSessionsNotSent() { | ||
_ = SentryEnvelope(event: Event()) | ||
let eventId = fixture.getSut(configureOptions: { options in | ||
|
@@ -1238,18 +1248,22 @@ class SentryClientTest: XCTestCase { | |
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertSampleRate is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testSampleRateNil_EventNotSampled() throws { | ||
try assertSampleRate(sampleRate: nil, randomValue: 0, isSampled: false) | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertSampleRate is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testSampleRateBiggerRandom_EventNotSampled() throws { | ||
try assertSampleRate(sampleRate: 0.5, randomValue: 0.49, isSampled: false) | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertSampleRate is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testSampleRateEqualsRandom_EventNotSampled() throws { | ||
try assertSampleRate(sampleRate: 0.5, randomValue: 0.5, isSampled: false) | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertSampleRate is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, these deprecation annotations can go away.") | ||
func testSampleRateSmallerRandom_EventSampled() throws { | ||
try assertSampleRate(sampleRate: 0.50, randomValue: 0.51, isSampled: true) | ||
} | ||
|
@@ -1464,22 +1478,45 @@ class SentryClientTest: XCTestCase { | |
XCTAssertEqual(fixture.transport.recordLostEventsWithCount.get(2)?.reason, SentryDiscardReason.beforeSend) | ||
XCTAssertEqual(fixture.transport.recordLostEventsWithCount.get(2)?.quantity, 1) | ||
} | ||
|
||
@available(*, deprecated, message: "-[SentryClient captureUserFeedback:] is deprecated. -[SentryClient captureFeedback:withScope:] is the new way. This test case can be removed in favor of testNoDsn_FeedbackNotSent when -[SentryClient captureUserFeedback:] is removed.") | ||
func testNoDsn_UserFeedbackNotSent() { | ||
let sut = fixture.getSutWithNoDsn() | ||
sut.capture(userFeedback: UserFeedback(eventId: SentryId())) | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "-[SentryClient captureUserFeedback:] is deprecated. -[SentryClient captureFeedback:withScope:] is the new way. This test case can be removed in favor of testDisabled_FeedbackNotSent when -[SentryClient captureUserFeedback:] is removed.") | ||
func testDisabled_UserFeedbackNotSent() { | ||
let sut = fixture.getSutDisabledSdk() | ||
sut.capture(userFeedback: UserFeedback(eventId: SentryId())) | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "-[SentryClient captureUserFeedback:] is deprecated. -[SentryClient captureFeedback:withScope:] is the new way. This test case can be removed in favor of testCaptureFeedback_WithEmptyEventId when -[SentryClient captureUserFeedback:] is removed.") | ||
func testCaptureUserFeedback_WithEmptyEventId() { | ||
let sut = fixture.getSut() | ||
sut.capture(userFeedback: UserFeedback(eventId: SentryId.empty)) | ||
sut.capture(userFeedback: UserFeedback(eventId: SentryId())) | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, this deprecation annotation can go away.") | ||
func testNoDsn_FeedbackNotSent() { | ||
let sut = fixture.getSutWithNoDsn() | ||
sut.capture(feedback: fixture.feedback, scope: fixture.scope) | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, this deprecation annotation can go away.") | ||
func testDisabled_FeedbackNotSent() { | ||
let sut = fixture.getSutDisabledSdk() | ||
sut.capture(feedback: fixture.feedback, scope: fixture.scope) | ||
assertNothingSent() | ||
} | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, this deprecation annotation can go away.") | ||
func testCaptureFeedback_WithEmptyEventId() { | ||
let sut = fixture.getSut() | ||
sut.capture(feedback: fixture.feedback, scope: fixture.scope) | ||
assertNothingSent() | ||
} | ||
|
||
|
@@ -2094,7 +2131,8 @@ private extension SentryClientTest { | |
private func shortenIntegrations(_ integrations: [String]?) -> [String]? { | ||
return integrations?.map { $0.replacingOccurrences(of: "Sentry", with: "").replacingOccurrences(of: "Integration", with: "") } | ||
} | ||
|
||
|
||
@available(*, deprecated, message: "Remove check on transportAdapter.userFeedbackInvocations when SentryUserFeedback is removed in favor of SentryFeedback. Then this deprecation annotation can be removed.") | ||
private func assertNothingSent() { | ||
XCTAssertTrue(fixture.transport.sentEnvelopes.isEmpty) | ||
XCTAssertEqual(0, fixture.transportAdapter.sentEventsWithSessionTraceState.count) | ||
|
@@ -2154,6 +2192,7 @@ private extension SentryClientTest { | |
} | ||
#endif | ||
|
||
@available(*, deprecated, message: "This is only marked as deprecated because assertNothingSent is marked as deprecated, due to it using a deprecated property inside it. When that property usage is removed, this deprecation annotations can be removed.") | ||
func assertSampleRate( sampleRate: NSNumber?, randomValue: Double, isSampled: Bool) throws { | ||
fixture.random.value = randomValue | ||
|
||
|
Oops, something went wrong.