-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated tests to remove Alamofire (#895)
Co-authored-by: Cody Garvin <cody.garvin@segment.com>
- Loading branch information
1 parent
be55af3
commit 7f2feed
Showing
4 changed files
with
37 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,42 @@ | ||
import Quick | ||
import Nimble | ||
import Analytics | ||
import Alamofire | ||
import Alamofire_Synchronous | ||
@testable import Analytics | ||
import XCTest | ||
|
||
func hasMatchingId(messageId: String) -> Bool { | ||
// End to End tests require some private credentials, so we can't embed them in source. | ||
// On CI, we inject these values with build settings (see Makefile test task). | ||
let runE2E = ProcessInfo.processInfo.environment["RUN_E2E_TESTS"] | ||
|
||
if runE2E != "true" { | ||
return true | ||
} | ||
|
||
guard let auth = ProcessInfo.processInfo.environment["WEBHOOK_AUTH_USERNAME"] else { | ||
fail("Cannot find webhook username") | ||
return false | ||
} | ||
|
||
let base64Token = SEGHTTPClient.authorizationHeader(auth) | ||
|
||
let headers: HTTPHeaders = [ | ||
"Authorization": "Basic \(base64Token)", | ||
] | ||
|
||
let response = Alamofire.request("https://webhook-e2e.segment.com/buckets/ios?limit=100", headers: headers).responseJSON() | ||
|
||
// TODO: This should be more strongly typed. | ||
let messages = response.result.value as! [String] | ||
|
||
for message in messages { | ||
if (message.contains("\"properties\":{\"id\":\"\(messageId)\"}")) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// End to End tests as described in https://paper.dropbox.com/doc/Libraries-End-to-End-Tests-ESEakc3LxFrqcHz69AmyN. | ||
// We connect a webhook destination to a Segment source, send some data to the source using the libray. Then we | ||
// verify that the data was sent to the source by finding it from the Webhook destination. | ||
class AnalyticsE2ETests: QuickSpec { | ||
override func spec() { | ||
class EndToEndTests: XCTestCase { | ||
|
||
var analytics: SEGAnalytics! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
// Write Key for https://app.segment.com/segment-libraries/sources/analytics_ios_e2e_test/overview | ||
let config = SEGAnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr") | ||
config.flushAt = 1 | ||
|
||
beforeEach { | ||
// Write Key for https://app.segment.com/segment-libraries/sources/analytics_ios_e2e_test/overview | ||
let config = SEGAnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr") | ||
config.flushAt = 1 | ||
SEGAnalytics.setup(with: config) | ||
|
||
SEGAnalytics.setup(with: config) | ||
|
||
analytics = SEGAnalytics.shared() | ||
analytics = SEGAnalytics.shared() | ||
} | ||
|
||
afterEach { | ||
analytics.reset() | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
|
||
analytics.reset() | ||
} | ||
|
||
it("track") { | ||
let uuid = UUID().uuidString | ||
self.expectation(forNotification: NSNotification.Name("SegmentRequestDidSucceed"), object: nil, handler: nil) | ||
|
||
analytics.track("E2E Test", properties: ["id": uuid]) | ||
|
||
self.waitForExpectations(timeout: 3 * 60) | ||
|
||
for _ in 1...3 * 30 { | ||
sleep(2) | ||
if hasMatchingId(messageId: uuid) { | ||
return | ||
|
||
func testTrack() { | ||
let uuid = UUID().uuidString | ||
let expectation = XCTestExpectation(description: "SegmentRequestDidSucceed") | ||
|
||
SEGAnalytics.shared()?.configuration.experimental.rawSegmentModificationBlock = { data in | ||
if let properties = data["properties"] as? Dictionary<String, Any?>, | ||
let tempUUID = properties["id"] as? String, tempUUID == uuid { | ||
expectation.fulfill() | ||
} | ||
return data | ||
} | ||
} | ||
|
||
fail("could not find message with id \(uuid) in Runscope") | ||
analytics.track("E2E Test", properties: ["id": uuid]) | ||
|
||
wait(for: [expectation], timeout: 2.0) | ||
} | ||
} | ||
} |
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