From 7553396d5d4d1191bb7b824ffc1e742f53fcd5e1 Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Thu, 8 Feb 2024 10:37:49 -0700 Subject: [PATCH 1/5] feat: add check for multiple instances using the same write-key --- .../BasicExample/BasicExample/AppDelegate.swift | 2 +- Sources/Segment/Analytics.swift | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift index e34f8114..385883f2 100644 --- a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift +++ b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - let configuration = Configuration(writeKey: "") + let configuration = Configuration(writeKey: "write-key") .trackApplicationLifecycleEvents(true) .flushInterval(10) .flushAt(2) diff --git a/Sources/Segment/Analytics.swift b/Sources/Segment/Analytics.swift index 4ea2b92b..c22ba104 100644 --- a/Sources/Segment/Analytics.swift +++ b/Sources/Segment/Analytics.swift @@ -68,6 +68,8 @@ public class Analytics { storage.analytics = self + + checkSharedWriteKeys() checkSharedInstance() // Get everything running @@ -423,6 +425,7 @@ extension Analytics { Self.firstInstance = self } } + // is firstInstance nil? If so, set it. if Self.firstInstance == nil { Self.firstInstance = self @@ -433,8 +436,20 @@ extension Analytics { internal var isDead: Bool { return configuration.values.writeKey == Self.deadInstance } + + private func checkSharedWriteKeys() { + if let firstInstance = Self.firstInstance { + if firstInstance !== self { + if firstInstance.configuration.values.writeKey == configuration.values.writeKey { + fatalError("Cannot initialize multiple instances of Analytics with the same write key") + } + } + } + } } + + // MARK: Operating mode based scheduling extension OperatingMode { From 3be1950514729d61d9a11e2da11e376ba7616b5d Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Thu, 8 Feb 2024 10:39:01 -0700 Subject: [PATCH 2/5] clean up --- Examples/apps/BasicExample/BasicExample/AppDelegate.swift | 2 +- Sources/Segment/Analytics.swift | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift index 385883f2..b165a176 100644 --- a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift +++ b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - let configuration = Configuration(writeKey: "write-key") + let configuration = Configuration(writeKey: "WRITE KEY") .trackApplicationLifecycleEvents(true) .flushInterval(10) .flushAt(2) diff --git a/Sources/Segment/Analytics.swift b/Sources/Segment/Analytics.swift index c22ba104..3a34d0b0 100644 --- a/Sources/Segment/Analytics.swift +++ b/Sources/Segment/Analytics.swift @@ -448,8 +448,6 @@ extension Analytics { } } - - // MARK: Operating mode based scheduling extension OperatingMode { From 444155f22c1c6914a3908e358beb89a28fb16fd3 Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Thu, 8 Feb 2024 10:39:37 -0700 Subject: [PATCH 3/5] cleanup write key placeholder --- Examples/apps/BasicExample/BasicExample/AppDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift index b165a176..e34f8114 100644 --- a/Examples/apps/BasicExample/BasicExample/AppDelegate.swift +++ b/Examples/apps/BasicExample/BasicExample/AppDelegate.swift @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - let configuration = Configuration(writeKey: "WRITE KEY") + let configuration = Configuration(writeKey: "") .trackApplicationLifecycleEvents(true) .flushInterval(10) .flushAt(2) From 3a955ee6470f6632db43ad150c84f1da9e1534ae Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Thu, 8 Feb 2024 12:27:23 -0700 Subject: [PATCH 4/5] add write key check to config --- Sources/Segment/Analytics.swift | 12 ----- Sources/Segment/Configuration.swift | 20 ++++++++ Tests/Segment-Tests/Analytics_Tests.swift | 52 ++++++++++---------- Tests/Segment-Tests/FlushPolicy_Tests.swift | 6 +-- Tests/Segment-Tests/MemoryLeak_Tests.swift | 2 +- Tests/Segment-Tests/ObjC_Tests.swift | 14 +++--- Tests/Segment-Tests/Storage_Tests.swift | 6 +-- Tests/Segment-Tests/Timeline_Tests.swift | 8 +-- Tests/Segment-Tests/iOSLifecycle_Tests.swift | 4 +- 9 files changed, 66 insertions(+), 58 deletions(-) diff --git a/Sources/Segment/Analytics.swift b/Sources/Segment/Analytics.swift index 3a34d0b0..78186d5e 100644 --- a/Sources/Segment/Analytics.swift +++ b/Sources/Segment/Analytics.swift @@ -68,8 +68,6 @@ public class Analytics { storage.analytics = self - - checkSharedWriteKeys() checkSharedInstance() // Get everything running @@ -436,16 +434,6 @@ extension Analytics { internal var isDead: Bool { return configuration.values.writeKey == Self.deadInstance } - - private func checkSharedWriteKeys() { - if let firstInstance = Self.firstInstance { - if firstInstance !== self { - if firstInstance.configuration.values.writeKey == configuration.values.writeKey { - fatalError("Cannot initialize multiple instances of Analytics with the same write key") - } - } - } - } } // MARK: Operating mode based scheduling diff --git a/Sources/Segment/Configuration.swift b/Sources/Segment/Configuration.swift index e77591cf..f2024dd3 100644 --- a/Sources/Segment/Configuration.swift +++ b/Sources/Segment/Configuration.swift @@ -25,6 +25,10 @@ public enum OperatingMode { // MARK: - Internal Configuration public class Configuration { + + internal let writeKeyLock: NSLock = NSLock() + static var activeWriteKeys: [String?] = [] + internal struct Values { var writeKey: String var application: Any? = nil @@ -59,6 +63,8 @@ public class Configuration { ]) self.defaultSettings(settings) + + checkActiveWriteKeys(writeKey: writeKey) } } @@ -233,6 +239,20 @@ public extension Configuration { JSON.jsonNonConformingNumberStrategy = values.jsonNonConformingNumberStrategy return self } + + func checkActiveWriteKeys(writeKey: String) { + writeKeyLock.lock() + + defer { + writeKeyLock.unlock() + } + + if Configuration.activeWriteKeys.contains(writeKey) { + fatalError("Cannot initialize multiple instances of Analytics with the same write key") + } else { + Configuration.activeWriteKeys.append(writeKey) + } + } } extension Analytics { diff --git a/Tests/Segment-Tests/Analytics_Tests.swift b/Tests/Segment-Tests/Analytics_Tests.swift index 7fc373ad..8d5669e1 100644 --- a/Tests/Segment-Tests/Analytics_Tests.swift +++ b/Tests/Segment-Tests/Analytics_Tests.swift @@ -16,7 +16,7 @@ final class Analytics_Tests: XCTestCase { } func testPluginConfigure() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test1")) let ziggy = ZiggyPlugin() let myDestination = MyDestination() let goober = GooberPlugin() @@ -31,7 +31,7 @@ final class Analytics_Tests: XCTestCase { } func testPluginRemove() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test2")) let myDestination = MyDestination() myDestination.add(plugin: GooberPlugin()) @@ -60,13 +60,13 @@ final class Analytics_Tests: XCTestCase { return true } - var settings = Settings(writeKey: "test") + var settings = Settings(writeKey: "test3") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[myDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test4") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) @@ -104,13 +104,13 @@ final class Analytics_Tests: XCTestCase { return true } - var settings = Settings(writeKey: "test") + var settings = Settings(writeKey: "test5") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[myDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test6") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) @@ -139,7 +139,7 @@ final class Analytics_Tests: XCTestCase { return true } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test7") let analytics = Analytics(configuration: configuration) analytics.add(plugin: myDestination) @@ -155,7 +155,7 @@ final class Analytics_Tests: XCTestCase { #endif func testAnonymousId() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test8")) let anonId = analytics.anonymousId XCTAssertTrue(anonId != "") @@ -163,7 +163,7 @@ final class Analytics_Tests: XCTestCase { } func testContext() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test9")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -211,7 +211,7 @@ final class Analytics_Tests: XCTestCase { func testContextWithUserAgent() { - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test10") configuration.userAgent("testing user agent") let analytics = Analytics(configuration: configuration) let outputReader = OutputReaderPlugin() @@ -257,7 +257,7 @@ final class Analytics_Tests: XCTestCase { } func testDeviceToken() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test11")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -274,7 +274,7 @@ final class Analytics_Tests: XCTestCase { #if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst) func testDeviceTokenData() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test12")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -292,7 +292,7 @@ final class Analytics_Tests: XCTestCase { #endif func testTrack() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test13")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -306,7 +306,7 @@ final class Analytics_Tests: XCTestCase { } func testIdentify() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test14")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -321,7 +321,7 @@ final class Analytics_Tests: XCTestCase { } func testUserIdAndTraitsPersistCorrectly() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test15")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -347,7 +347,7 @@ final class Analytics_Tests: XCTestCase { func testScreen() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test16")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -369,7 +369,7 @@ final class Analytics_Tests: XCTestCase { } func testGroup() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test17")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -389,7 +389,7 @@ final class Analytics_Tests: XCTestCase { } func testReset() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test25")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -437,7 +437,7 @@ final class Analytics_Tests: XCTestCase { } func testEnabled() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test19")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -479,7 +479,7 @@ final class Analytics_Tests: XCTestCase { } func testSetFlushAtAfter() { - let analytics = Analytics(configuration: Configuration(writeKey: "1234")) + let analytics = Analytics(configuration: Configuration(writeKey: "12345")) let countPolicy = CountBasedFlushPolicy(count: 23) analytics.add(flushPolicy: countPolicy) @@ -540,7 +540,7 @@ final class Analytics_Tests: XCTestCase { } func testVersion() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test18")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -571,7 +571,7 @@ final class Analytics_Tests: XCTestCase { // Test to ensure bundled and unbundled integrations are populated correctly func testDestinationMetadata() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test20")) let mixpanel = AnyDestination(key: "Mixpanel") let outputReader = OutputReaderPlugin() @@ -610,7 +610,7 @@ final class Analytics_Tests: XCTestCase { // Test to ensure bundled and active integrations are populated correctly func testDestinationMetadataUnbundled() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test21")) let mixpanel = AnyDestination(key: "Mixpanel") let outputReader = OutputReaderPlugin() @@ -721,7 +721,7 @@ final class Analytics_Tests: XCTestCase { let dead = Analytics.shared() XCTAssertTrue(dead.isDead) - let alive = Analytics(configuration: Configuration(writeKey: "1234")) + let alive = Analytics(configuration: Configuration(writeKey: "123456")) XCTAssertFalse(alive.isDead) let shared = Analytics.shared() @@ -826,7 +826,7 @@ final class Analytics_Tests: XCTestCase { func testJSONNaNDefaultHandlingZero() throws { // notice we didn't set the nan handling option. zero is the default. - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test22")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -842,7 +842,7 @@ final class Analytics_Tests: XCTestCase { } func testJSONNaNHandlingNull() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "test") + let analytics = Analytics(configuration: Configuration(writeKey: "test23") .jsonNonConformingNumberStrategy(.null) ) let outputReader = OutputReaderPlugin() diff --git a/Tests/Segment-Tests/FlushPolicy_Tests.swift b/Tests/Segment-Tests/FlushPolicy_Tests.swift index 0de096c0..4159a9b1 100644 --- a/Tests/Segment-Tests/FlushPolicy_Tests.swift +++ b/Tests/Segment-Tests/FlushPolicy_Tests.swift @@ -55,7 +55,7 @@ class FlushPolicyTests: XCTestCase { } func testRemoveFlushPolicy() { - let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest")) + let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest1")) let dummy = DummyFlushPolicy() analytics.add(flushPolicy: dummy) @@ -72,7 +72,7 @@ class FlushPolicyTests: XCTestCase { } func testRemoveAllFlushPolicies() { - let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest")) + let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest2")) var policies = analytics.configuration.values.flushPolicies waitUntilStarted(analytics: analytics) @@ -87,7 +87,7 @@ class FlushPolicyTests: XCTestCase { } func testFindFlushPolicy() { - let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest")) + let analytics = Analytics(configuration: Configuration(writeKey: "flushPolicyAddTest3")) waitUntilStarted(analytics: analytics) diff --git a/Tests/Segment-Tests/MemoryLeak_Tests.swift b/Tests/Segment-Tests/MemoryLeak_Tests.swift index cff3e72e..9570e191 100644 --- a/Tests/Segment-Tests/MemoryLeak_Tests.swift +++ b/Tests/Segment-Tests/MemoryLeak_Tests.swift @@ -95,7 +95,7 @@ final class MemoryLeak_Tests: XCTestCase { } func testLeaksSimple() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "1234")) + let analytics = Analytics(configuration: Configuration(writeKey: "12345")) waitUntilStarted(analytics: analytics) analytics.track(name: "test") diff --git a/Tests/Segment-Tests/ObjC_Tests.swift b/Tests/Segment-Tests/ObjC_Tests.swift index 55d232c0..2ee136b2 100644 --- a/Tests/Segment-Tests/ObjC_Tests.swift +++ b/Tests/Segment-Tests/ObjC_Tests.swift @@ -28,7 +28,7 @@ class ObjC_Tests: XCTestCase { */ func testWrapping() { - let a = Analytics(configuration: Configuration(writeKey: "WRITE_KEY")) + let a = Analytics(configuration: Configuration(writeKey: "WRITE_KEY0")) let objc = ObjCAnalytics(wrapping: a) XCTAssertTrue(objc.analytics === a) @@ -47,7 +47,7 @@ class ObjC_Tests: XCTestCase { func testNonTrivialAnalytics() { Storage.hardSettingsReset(writeKey: "WRITE_KEY") - let config = ObjCConfiguration(writeKey: "WRITE_KEY") + let config = ObjCConfiguration(writeKey: "WRITE_KEY1") config.defaultSettings = ["integrations": ["Amplitude": true]] let analytics = ObjCAnalytics(configuration: config) @@ -72,7 +72,7 @@ class ObjC_Tests: XCTestCase { } func testTraitsAndUserIdOptionality() { - let config = ObjCConfiguration(writeKey: "WRITE_KEY") + let config = ObjCConfiguration(writeKey: "WRITE_KEY2") let analytics = ObjCAnalytics(configuration: config) analytics.reset() @@ -90,9 +90,9 @@ class ObjC_Tests: XCTestCase { var sourceHit: Bool = false var destHit: Bool = false - Storage.hardSettingsReset(writeKey: "WRITE_KEY") + Storage.hardSettingsReset(writeKey: "WRITE_KEY2") - let config = ObjCConfiguration(writeKey: "WRITE_KEY") + let config = ObjCConfiguration(writeKey: "WRITE_KEY3") let analytics = ObjCAnalytics(configuration: config) analytics.analytics.storage.hardReset(doYouKnowHowToUseThis: true) @@ -132,9 +132,9 @@ class ObjC_Tests: XCTestCase { } func testObjCDictionaryPassThru() { - Storage.hardSettingsReset(writeKey: "WRITE_KEY2") + Storage.hardSettingsReset(writeKey: "WRITE_KEY3") - let config = ObjCConfiguration(writeKey: "WRITE_KEY2") + let config = ObjCConfiguration(writeKey: "WRITE_KEY4") let analytics = ObjCAnalytics(configuration: config) analytics.analytics.storage.hardReset(doYouKnowHowToUseThis: true) diff --git a/Tests/Segment-Tests/Storage_Tests.swift b/Tests/Segment-Tests/Storage_Tests.swift index a9690782..e78b5d12 100644 --- a/Tests/Segment-Tests/Storage_Tests.swift +++ b/Tests/Segment-Tests/Storage_Tests.swift @@ -69,7 +69,7 @@ class StorageTests: XCTestCase { } func testBasicWriting() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test1")) analytics.identify(userId: "brandon", traits: MyTraits(email: "blah@blah.com")) @@ -88,7 +88,7 @@ class StorageTests: XCTestCase { } func testEventWriting() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test2")) analytics.storage.hardReset(doYouKnowHowToUseThis: true) var event = IdentifyEvent(userId: "brandon1", traits: try! JSON(with: MyTraits(email: "blah@blah.com"))) @@ -131,7 +131,7 @@ class StorageTests: XCTestCase { } func testFilePrepAndFinish() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test3")) analytics.storage.hardReset(doYouKnowHowToUseThis: true) var event = IdentifyEvent(userId: "brandon1", traits: try! JSON(with: MyTraits(email: "blah@blah.com"))) diff --git a/Tests/Segment-Tests/Timeline_Tests.swift b/Tests/Segment-Tests/Timeline_Tests.swift index 04a2ea92..22e92990 100644 --- a/Tests/Segment-Tests/Timeline_Tests.swift +++ b/Tests/Segment-Tests/Timeline_Tests.swift @@ -53,14 +53,14 @@ class Timeline_Tests: XCTestCase { // Do this to force enable the destination - var settings = Settings(writeKey: "test") + var settings = Settings(writeKey: "test1") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[firstDestination.key] = true newIntegrations[secondDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test1") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) @@ -89,14 +89,14 @@ class Timeline_Tests: XCTestCase { // Do this to force enable the destination - var settings = Settings(writeKey: "test") + var settings = Settings(writeKey: "test2") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[firstDestination.key] = true newIntegrations[secondDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test2") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) diff --git a/Tests/Segment-Tests/iOSLifecycle_Tests.swift b/Tests/Segment-Tests/iOSLifecycle_Tests.swift index 44fff33f..36e52885 100644 --- a/Tests/Segment-Tests/iOSLifecycle_Tests.swift +++ b/Tests/Segment-Tests/iOSLifecycle_Tests.swift @@ -27,7 +27,7 @@ final class iOSLifecycle_Tests: XCTestCase { } func testInstallEventUpdated() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test1")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -49,7 +49,7 @@ final class iOSLifecycle_Tests: XCTestCase { } func testInstallEventOpened() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test2")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) From 528bd77a92b961db3699bf93ce6ce6b340959f01 Mon Sep 17 00:00:00 2001 From: Alan Charles Date: Thu, 8 Feb 2024 12:47:35 -0700 Subject: [PATCH 5/5] fix test write keys --- Tests/Segment-Tests/MemoryLeak_Tests.swift | 4 ++-- Tests/Segment-Tests/Storage_Tests.swift | 8 ++++---- Tests/Segment-Tests/Timeline_Tests.swift | 10 +++++----- Tests/Segment-Tests/iOSLifecycle_Tests.swift | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Tests/Segment-Tests/MemoryLeak_Tests.swift b/Tests/Segment-Tests/MemoryLeak_Tests.swift index 9570e191..2686e17e 100644 --- a/Tests/Segment-Tests/MemoryLeak_Tests.swift +++ b/Tests/Segment-Tests/MemoryLeak_Tests.swift @@ -19,7 +19,7 @@ final class MemoryLeak_Tests: XCTestCase { } func testLeaksVerbose() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "1234")) + let analytics = Analytics(configuration: Configuration(writeKey: "memory_test_verbose")) waitUntilStarted(analytics: analytics) analytics.track(name: "test") @@ -95,7 +95,7 @@ final class MemoryLeak_Tests: XCTestCase { } func testLeaksSimple() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "12345")) + let analytics = Analytics(configuration: Configuration(writeKey: "memory_leak_test_simple")) waitUntilStarted(analytics: analytics) analytics.track(name: "test") diff --git a/Tests/Segment-Tests/Storage_Tests.swift b/Tests/Segment-Tests/Storage_Tests.swift index e78b5d12..553f77f0 100644 --- a/Tests/Segment-Tests/Storage_Tests.swift +++ b/Tests/Segment-Tests/Storage_Tests.swift @@ -54,7 +54,7 @@ class StorageTests: XCTestCase { let jsonData = dummySettings.data(using: .utf8)! let jsonSettings = try! JSONSerialization.jsonObject(with: jsonData) - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_settings_write")) analytics.storage.hardReset(doYouKnowHowToUseThis: true) // this will crash if it fails. @@ -69,7 +69,7 @@ class StorageTests: XCTestCase { } func testBasicWriting() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "test1")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_basic_settings_write")) analytics.identify(userId: "brandon", traits: MyTraits(email: "blah@blah.com")) @@ -88,7 +88,7 @@ class StorageTests: XCTestCase { } func testEventWriting() throws { - let analytics = Analytics(configuration: Configuration(writeKey: "test2")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_basic_event_write")) analytics.storage.hardReset(doYouKnowHowToUseThis: true) var event = IdentifyEvent(userId: "brandon1", traits: try! JSON(with: MyTraits(email: "blah@blah.com"))) @@ -131,7 +131,7 @@ class StorageTests: XCTestCase { } func testFilePrepAndFinish() { - let analytics = Analytics(configuration: Configuration(writeKey: "test3")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_file_prep")) analytics.storage.hardReset(doYouKnowHowToUseThis: true) var event = IdentifyEvent(userId: "brandon1", traits: try! JSON(with: MyTraits(email: "blah@blah.com"))) diff --git a/Tests/Segment-Tests/Timeline_Tests.swift b/Tests/Segment-Tests/Timeline_Tests.swift index 22e92990..49634700 100644 --- a/Tests/Segment-Tests/Timeline_Tests.swift +++ b/Tests/Segment-Tests/Timeline_Tests.swift @@ -26,7 +26,7 @@ class Timeline_Tests: XCTestCase { return true } - let configuration = Configuration(writeKey: "test") + let configuration = Configuration(writeKey: "test_base_event_creation") let analytics = Analytics(configuration: configuration) analytics.add(plugin: firstDestination) @@ -53,14 +53,14 @@ class Timeline_Tests: XCTestCase { // Do this to force enable the destination - var settings = Settings(writeKey: "test1") + var settings = Settings(writeKey: "test_two_base_event_creation") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[firstDestination.key] = true newIntegrations[secondDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test1") + let configuration = Configuration(writeKey: "test_two_base_event_creation") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) @@ -89,14 +89,14 @@ class Timeline_Tests: XCTestCase { // Do this to force enable the destination - var settings = Settings(writeKey: "test2") + var settings = Settings(writeKey: "test_base_event_creation_first_fail") if let existing = settings.integrations?.dictionaryValue { var newIntegrations = existing newIntegrations[firstDestination.key] = true newIntegrations[secondDestination.key] = true settings.integrations = try! JSON(newIntegrations) } - let configuration = Configuration(writeKey: "test2") + let configuration = Configuration(writeKey: "test_base_event_creation_first_fail") configuration.defaultSettings(settings) let analytics = Analytics(configuration: configuration) diff --git a/Tests/Segment-Tests/iOSLifecycle_Tests.swift b/Tests/Segment-Tests/iOSLifecycle_Tests.swift index 36e52885..0c84d1bc 100644 --- a/Tests/Segment-Tests/iOSLifecycle_Tests.swift +++ b/Tests/Segment-Tests/iOSLifecycle_Tests.swift @@ -5,7 +5,7 @@ import XCTest final class iOSLifecycle_Tests: XCTestCase { func testInstallEventCreation() { - let analytics = Analytics(configuration: Configuration(writeKey: "test")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_install_event_creation")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -27,7 +27,7 @@ final class iOSLifecycle_Tests: XCTestCase { } func testInstallEventUpdated() { - let analytics = Analytics(configuration: Configuration(writeKey: "test1")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_install_event_updated")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader) @@ -49,7 +49,7 @@ final class iOSLifecycle_Tests: XCTestCase { } func testInstallEventOpened() { - let analytics = Analytics(configuration: Configuration(writeKey: "test2")) + let analytics = Analytics(configuration: Configuration(writeKey: "test_install_event_opened")) let outputReader = OutputReaderPlugin() analytics.add(plugin: outputReader)