Skip to content

Commit

Permalink
Merge pull request #566 from DataDog/maxep/RUMM-1530-add-init-check
Browse files Browse the repository at this point in the history
RUMM-1530 Add Datadog.isInitialized variable
  • Loading branch information
maxep authored Aug 20, 2021
2 parents 64e9ee8 + 94634cb commit 8b3a8ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Sources/Datadog/Datadog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public class Datadog {
}
}

/// Returns `true` if the Datadog SDK is already initialized, `false` otherwise.
public static var isInitialized: Bool {
return instance != nil
}

/// Sets current user information.
/// Those will be added to logs, traces and RUM events automatically.
/// - Parameters:
Expand Down
10 changes: 5 additions & 5 deletions Tests/DatadogTests/Datadog/DatadogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class DatadogTests: XCTestCase {

override func setUp() {
super.setUp()
XCTAssertNil(Datadog.instance)
XCTAssertFalse(Datadog.isInitialized)
printFunction = PrintFunctionMock()
consolePrint = printFunction.print
}

override func tearDown() {
consolePrint = { print($0) }
printFunction = nil
XCTAssertNil(Datadog.instance)
XCTAssertFalse(Datadog.isInitialized)
super.tearDown()
}

Expand All @@ -38,7 +38,7 @@ class DatadogTests: XCTestCase {
trackingConsent: .mockRandom(),
configuration: defaultBuilder.build()
)
XCTAssertNotNil(Datadog.instance)
XCTAssertTrue(Datadog.isInitialized)
Datadog.flushAndDeinitialize()
}

Expand All @@ -48,7 +48,7 @@ class DatadogTests: XCTestCase {
trackingConsent: .mockRandom(),
configuration: rumBuilder.build()
)
XCTAssertNotNil(Datadog.instance)
XCTAssertTrue(Datadog.isInitialized)
Datadog.flushAndDeinitialize()
}

Expand All @@ -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() {
Expand Down

0 comments on commit 8b3a8ed

Please sign in to comment.