Skip to content

Commit

Permalink
Also warn if DATADOG_CLIENT_TOKEN or SRCROOT are not properly set
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Bonafonte committed Jun 11, 2021
1 parent 9532975 commit a12ce50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/DatadogSDKTesting/FrameworkLoadHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FrameworkLoadHandler: NSObject {

internal static func installTestObserver() {
/// Only initialize test observer if user configured so and is running tests
guard let enabled = DDEnvironmentValues.getEnvVariable("DD_TEST_RUNNER") as NSString? else {
guard let enabled = environment["DD_TEST_RUNNER"] as NSString? else {
print("[DatadogSDKTesting] Library loaded but not active, DD_TEST_RUNNER is missing")
return
}
Expand All @@ -29,6 +29,13 @@ public class FrameworkLoadHandler: NSObject {
let isInTestMode = environment["XCInjectBundleInto"] != nil ||
environment["XCTestConfigurationFilePath"] != nil
if isInTestMode {
guard environment["DATADOG_CLIENT_TOKEN"] != nil else {
print("[DatadogSDKTesting] DATADOG_CLIENT_TOKEN missing.")
return
}
if environment["SRCROOT"] == nil {
print("[DatadogSDKTesting] SRCROOT is not properly set")
}
print("[DatadogSDKTesting] Library loaded and active. Instrumenting tests.")
DDTestMonitor.instance = DDTestMonitor()
DDTestMonitor.instance?.startInstrumenting()
Expand Down
13 changes: 13 additions & 0 deletions Tests/DatadogSDKTesting/FrameworkLoadHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FrameworkLoadHandlerTests: XCTestCase {

func testWhenTestRunnerIsConfiguredAndIsInTestingMode_ItIsInitialised() {
testEnvironment["DD_TEST_RUNNER"] = "1"
testEnvironment["DATADOG_CLIENT_TOKEN"] = "fakeToken"
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
testEnvironment["XCTestConfigurationFilePath"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
setEnvVariables()
Expand All @@ -47,6 +48,7 @@ class FrameworkLoadHandlerTests: XCTestCase {

func testWhenTestRunnerIsConfiguredAndIsInOtherTestingMode_ItIsInitialised() {
testEnvironment["DD_TEST_RUNNER"] = "1"
testEnvironment["DATADOG_CLIENT_TOKEN"] = "fakeToken"
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
testEnvironment["XCInjectBundleInto"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
setEnvVariables()
Expand All @@ -56,6 +58,17 @@ class FrameworkLoadHandlerTests: XCTestCase {
XCTAssertNotNil(DDTestMonitor.instance)
}

func testWhenTestRunnerIsConfiguredAndIsInTestingModeButNoToken_ItIsNotInitialised() {
testEnvironment["DD_TEST_RUNNER"] = "1"
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
testEnvironment["XCTestConfigurationFilePath"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
setEnvVariables()

FrameworkLoadHandler.handleLoad()

XCTAssertNil(DDTestMonitor.instance)
}

func testWhenTestRunnerIsNotConfigured_ItIsNotInitialised() {
testEnvironment["XCInjectBundleInto"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
setEnvVariables()
Expand Down

0 comments on commit a12ce50

Please sign in to comment.