Skip to content

Commit

Permalink
Updated tests to remove Alamofire (#895)
Browse files Browse the repository at this point in the history
Co-authored-by: Cody Garvin <cody.garvin@segment.com>
  • Loading branch information
migs647 and Cody-Segment authored May 29, 2020
1 parent be55af3 commit 7f2feed
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 94 deletions.
14 changes: 3 additions & 11 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
63E090D722DD49C300DEC7EC /* UIViewController+SegScreenTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+SegScreenTest.h"; sourceTree = "<group>"; };
66058A0DB75544E7C2766C31 /* Pods_AnalyticsTestsTVOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AnalyticsTestsTVOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6E265C781FB1178C0030E08E /* IntegrationsManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationsManagerTest.swift; sourceTree = "<group>"; };
6EEC1C702017EA370089C478 /* EndToEndTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndToEndTests.swift; sourceTree = "<group>"; };
6EEC1C702017EA370089C478 /* EndToEndTests.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = EndToEndTests.swift; sourceTree = "<group>"; tabWidth = 4; };
9D8CE5A723EE014E00197D0C /* AnalyticsTestsTVOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AnalyticsTestsTVOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A31958EE2385AC3A00A47EFA /* SerializationTests.m */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = SerializationTests.m; sourceTree = "<group>"; tabWidth = 4; };
A352175F23AD5825005B07F6 /* SEGMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SEGMacros.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,10 +321,10 @@
5AF0E8457CCFC077382BF449 /* AutoScreenReportingTest.swift */,
63E090D722DD49C300DEC7EC /* UIViewController+SegScreenTest.h */,
);
indentWidth = 2;
indentWidth = 4;
path = AnalyticsTests;
sourceTree = "<group>";
tabWidth = 2;
tabWidth = 4;
};
EADEB8751DECD12B005322DA /* Classes */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -615,17 +615,13 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire-iOS/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/Alamofire-Synchronous-iOS/Alamofire_Synchronous.framework",
"${BUILT_PRODUCTS_DIR}/Nimble-iOS/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Nocilla-iOS/Nocilla.framework",
"${BUILT_PRODUCTS_DIR}/Quick-iOS/Quick.framework",
"${BUILT_PRODUCTS_DIR}/SwiftTryCatch-iOS/SwiftTryCatch.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire_Synchronous.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
Expand Down Expand Up @@ -687,17 +683,13 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTestsTVOS/Pods-AnalyticsTestsTVOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire-tvOS/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/Alamofire-Synchronous-tvOS/Alamofire_Synchronous.framework",
"${BUILT_PRODUCTS_DIR}/Nimble-tvOS/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Nocilla-tvOS/Nocilla.framework",
"${BUILT_PRODUCTS_DIR}/Quick-tvOS/Quick.framework",
"${BUILT_PRODUCTS_DIR}/SwiftTryCatch-tvOS/SwiftTryCatch.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire_Synchronous.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
Expand Down
102 changes: 32 additions & 70 deletions AnalyticsTests/EndToEndTests.swift
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)
}
}
}
2 changes: 0 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ def shared_testing_pods
pod 'Quick', '~> 1.2.0'
pod 'Nimble', '~> 7.3.4'
pod 'Nocilla', '~> 0.11.0'
pod 'Alamofire', '~> 4.5'
pod 'Alamofire-Synchronous', '~> 4.0'
pod 'SwiftTryCatch', :git => 'https://github.com/segmentio/SwiftTryCatch.git'
end

Expand Down
13 changes: 2 additions & 11 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
PODS:
- Alamofire (4.6.0)
- Alamofire-Synchronous (4.0.0):
- Alamofire (~> 4.0)
- Nimble (7.3.4)
- Nocilla (0.11.0)
- Quick (1.2.0)
- SwiftTryCatch (1.0.0)

DEPENDENCIES:
- Alamofire (~> 4.5)
- Alamofire-Synchronous (~> 4.0)
- Nimble (~> 7.3.4)
- Nocilla (~> 0.11.0)
- Quick (~> 1.2.0)
- SwiftTryCatch (from `https://github.com/segmentio/SwiftTryCatch.git`)

SPEC REPOS:
trunk:
- Alamofire
- Alamofire-Synchronous
- Nimble
- Nocilla
- Quick
Expand All @@ -33,13 +26,11 @@ CHECKOUT OPTIONS:
:git: https://github.com/segmentio/SwiftTryCatch.git

SPEC CHECKSUMS:
Alamofire: f41a599bd63041760b26d393ec1069d9d7b917f4
Alamofire-Synchronous: eedf1e6e961c3795a63c74990b3f7d9fbfac7e50
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Nocilla: 7af7a386071150cc8aa5da4da97d060f049dd61c
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
SwiftTryCatch: 6ef1f543b5d287a4f5763c0de2ee9c8568985269

PODFILE CHECKSUM: bb5abec39a698f101923cddb294d2dfb1b19f105
PODFILE CHECKSUM: 80d573cfd1dc222ba558c64e15bef5eb9d22c782

COCOAPODS: 1.9.1
COCOAPODS: 1.9.2

0 comments on commit 7f2feed

Please sign in to comment.