From 8e7f0111c8a68123acc8ba6dbae56e7027e5788b Mon Sep 17 00:00:00 2001 From: maxep Date: Wed, 18 Aug 2021 14:40:30 +0200 Subject: [PATCH 1/2] RUMM-1530 Add `Datadog.isInitialized` variable --- Sources/Datadog/Datadog.swift | 5 +++++ Tests/DatadogTests/Datadog/DatadogTests.swift | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/Datadog/Datadog.swift b/Sources/Datadog/Datadog.swift index c02374bec5..7bdad2aa00 100644 --- a/Sources/Datadog/Datadog.swift +++ b/Sources/Datadog/Datadog.swift @@ -102,6 +102,11 @@ public class Datadog { } } + /// Returns `true` if the Datadog SDK is already initialized, `false` otherwise. + public static var isInitialized: Bool { + instance != nil + } + /// Sets current user information. /// Those will be added to logs, traces and RUM events automatically. /// - Parameters: diff --git a/Tests/DatadogTests/Datadog/DatadogTests.swift b/Tests/DatadogTests/Datadog/DatadogTests.swift index 88ea4cf0af..85cb36b22f 100644 --- a/Tests/DatadogTests/Datadog/DatadogTests.swift +++ b/Tests/DatadogTests/Datadog/DatadogTests.swift @@ -18,7 +18,7 @@ class DatadogTests: XCTestCase { override func setUp() { super.setUp() - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) printFunction = PrintFunctionMock() consolePrint = printFunction.print } @@ -26,7 +26,7 @@ class DatadogTests: XCTestCase { override func tearDown() { consolePrint = { print($0) } printFunction = nil - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) super.tearDown() } @@ -38,7 +38,7 @@ class DatadogTests: XCTestCase { trackingConsent: .mockRandom(), configuration: defaultBuilder.build() ) - XCTAssertNotNil(Datadog.instance) + XCTAssertTrue(Datadog.isInitialized) Datadog.flushAndDeinitialize() } @@ -48,7 +48,7 @@ class DatadogTests: XCTestCase { trackingConsent: .mockRandom(), configuration: rumBuilder.build() ) - XCTAssertNotNil(Datadog.instance) + XCTAssertTrue(Datadog.isInitialized) Datadog.flushAndDeinitialize() } @@ -67,7 +67,7 @@ class DatadogTests: XCTestCase { printFunction.printedMessage, "🔥 Datadog SDK usage error: `clientToken` cannot be empty." ) - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) } func testGivenValidConfiguration_whenInitializedMoreThanOnce_itPrintsError() { From 94634cb3a211215b0b9800d203be98de54edad53 Mon Sep 17 00:00:00 2001 From: maxep Date: Wed, 18 Aug 2021 17:26:24 +0200 Subject: [PATCH 2/2] Avoid implicit return --- Sources/Datadog/Datadog.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Datadog/Datadog.swift b/Sources/Datadog/Datadog.swift index 7bdad2aa00..872daca099 100644 --- a/Sources/Datadog/Datadog.swift +++ b/Sources/Datadog/Datadog.swift @@ -104,7 +104,7 @@ public class Datadog { /// Returns `true` if the Datadog SDK is already initialized, `false` otherwise. public static var isInitialized: Bool { - instance != nil + return instance != nil } /// Sets current user information.