Skip to content

Commit

Permalink
Use schema webhook (#766)
Browse files Browse the repository at this point in the history
Runscope shutdown the traffic inspector (https://blog.runscope.com/posts/phasing-out-traffic-inspector) we were using for our tests.

This migrates to the custom webhook replacement we had built.

Also removes unused xctool commands/updates their usage.

Ref: LIB-458
  • Loading branch information
f2prateek authored and fathyb committed Jul 12, 2018
1 parent 696b23d commit 7a8f7d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
46 changes: 23 additions & 23 deletions AnalyticsTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import Alamofire_Synchronous
// End to End tests require some private credentials, so we can't embed them in source.
// On CI, we inject these values with sed (see circle config for exact command).
let RUN_E2E_TESTS = false
let RUNSCOPE_TOKEN = "{RUNSCOPE_TOKEN}"
let WEBHOOK_AUTH_USERNAME = "{WEBHOOK_AUTH_USERNAME}"

func hasMatchingId(messageId: String) -> Bool {
if !RUN_E2E_TESTS {
return true
}


let base64Token = SEGHTTPClient.authorizationHeader(WEBHOOK_AUTH_USERNAME)

let headers: HTTPHeaders = [
"Authorization": "Bearer \(RUNSCOPE_TOKEN)",
"Authorization": "Basic \(base64Token)",
]

// Runscope Bucket for https://www.runscope.com/stream/uh9834m87jz5
let response = Alamofire.request("https://api.runscope.com/buckets/uh9834m87jz5/messages?count=10", headers: headers).responseJSON()
for message in (response.result.value as! [String: Any])["data"] as! [[String: Any]] {
let uuid = message["uuid"] as! String

let response = Alamofire.request("https://api.runscope.com/buckets/uh9834m87jz5/messages/\(uuid)", headers: headers).responseJSON()
let body = (((response.result.value as! [String: Any])["data"] as! [String: Any])["request"] as! [String: Any])["body"] as! String

if (body.contains("\"properties\":{\"id\":\"\(messageId)\"}")) {

let response = Alamofire.request("https://webhook-e2e.segment.com/buckets/ios?limit=10", 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
}

Expand All @@ -40,36 +40,36 @@ func hasMatchingId(messageId: String) -> Bool {
class AnalyticsE2ETests: QuickSpec {
override func spec() {
var analytics: SEGAnalytics!

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)

analytics = SEGAnalytics.shared()
}

afterEach {
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: 20)

for _ in 1...5 {
sleep(2)
if hasMatchingId(messageId: uuid) {
return
}
}

fail("could not find message with id \(uuid) in Runscope")
}
}
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ build-pretty:
test-pretty:
set -o pipefail && xcodebuild test $(XC_ARGS) $(XC_TEST_ARGS) | xcpretty --report junit

xcbuild:
xctool $(XC_ARGS)

xctest:
xctool test $(XC_ARGS)
xctool $(XC_ARGS) run-tests

.PHONY: bootstrap lint carthage archive test xctest build xcbuild clean
.PHONY: bootstrap lint carthage archive build test xctest clean
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
test:
override:
- sed -i -e 's/RUN_E2E_TESTS = false/RUN_E2E_TESTS = '"$RUN_E2E_TESTS"'/g' AnalyticsTests/EndToEndTests.swift
- sed -i -e 's/RUNSCOPE_TOKEN = "{RUNSCOPE_TOKEN}"/RUNSCOPE_TOKEN = "'"$RUNSCOPE_TOKEN"'"/g' AnalyticsTests/EndToEndTests.swift
- sed -i -e 's/WEBHOOK_AUTH_USERNAME = "{WEBHOOK_AUTH_USERNAME}"/WEBHOOK_AUTH_USERNAME = "'"$WEBHOOK_AUTH_USERNAME"'"/g' AnalyticsTests/EndToEndTests.swift
- make build-pretty
- make test-pretty
- make lint
Expand Down

0 comments on commit 7a8f7d3

Please sign in to comment.