-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16dc71d
commit 2f8c258
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { DiagLogLevel } from "@opentelemetry/api" | ||
import { ExtendedSwConfiguration, readConfig } from "../src/config" | ||
import { describe, it, expect, beforeEach } from "@solarwinds-apm/test" | ||
import { oboe } from "@solarwinds-apm/bindings" | ||
|
||
describe("readConfig", () => { | ||
beforeEach(() => { | ||
for (const key of Object.keys(process.env)) { | ||
if (key.startsWith("SW_APM_")) Reflect.deleteProperty(process.env, key) | ||
} | ||
process.env.SW_APM_SERVICE_KEY = "token:name" | ||
}) | ||
|
||
it("returns proper defaults", () => { | ||
const config = readConfig() | ||
const expected: ExtendedSwConfiguration = { | ||
token: "token", | ||
serviceName: "name", | ||
enabled: true, | ||
otelLogLevel: DiagLogLevel.INFO, | ||
oboeLogLevel: oboe.DEBUG_INFO, | ||
triggerTraceEnabled: true, | ||
runtimeMetrics: true, | ||
insertTraceContextIntoLogs: false, | ||
insertTraceContextIntoQueries: false, | ||
} | ||
|
||
expect(config).to.deep.include(expected) | ||
}) | ||
|
||
it("parses booleans", () => { | ||
process.env.SW_APM_ENABLED = "0" | ||
|
||
const config = readConfig() | ||
expect(config).to.include({ enabled: false }) | ||
}) | ||
|
||
it("parses tracing mode", () => { | ||
process.env.SW_APM_TRACING_MODE = "enabled" | ||
|
||
const config = readConfig() | ||
expect(config).to.include({ tracingMode: true }) | ||
}) | ||
|
||
it("parses trusted path", () => { | ||
process.env.SW_APM_TRUSTED_PATH = "package.json" | ||
|
||
const config = readConfig() | ||
expect(config.certificate).to.include("solarwinds-apm") | ||
}) | ||
|
||
it("parses transaction settings", () => { | ||
process.env.SW_APM_CONFIG_FILE = "test/test.config.js" | ||
|
||
const config = readConfig() | ||
expect(config.transactionSettings).not.to.be.undefined | ||
expect(config.transactionSettings).to.have.length(3) | ||
}) | ||
|
||
it("throws on bad boolean", () => { | ||
process.env.SW_APM_ENABLED = "foo" | ||
|
||
expect(readConfig).to.throw() | ||
}) | ||
|
||
it("throws on bad tracing mode", () => { | ||
process.env.SW_APM_TRACING_MODE = "foo" | ||
|
||
expect(readConfig).to.throw() | ||
}) | ||
|
||
it("throws on non-existent trusted path", () => { | ||
process.env.SW_APM_TRUSTED_PATH = "foo" | ||
|
||
expect(readConfig).to.throw() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
transactionSettings: [ | ||
{ tracing: "enabled", regex: /^hello$/ }, | ||
{ tracing: "disabled", regex: "[A-Z]" }, | ||
{ tracing: "enabled", matcher: (ident) => ident.startsWith("foo") }, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.test.json", | ||
"references": [{ "path": "../tsconfig.json" }] | ||
} |