Skip to content

Commit

Permalink
Add/fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikostoulas committed Oct 3, 2023
1 parent 894c7c3 commit d19a3dc
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 84 deletions.
133 changes: 63 additions & 70 deletions __snapshots__/diamorphosis.test.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports['Diamorphosis Test should set json/console loggingvariables when nothing
},
"printLogo": true,
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "debug",
"console": true,
"json": false
Expand Down Expand Up @@ -192,32 +192,31 @@ exports['Diamorphosis Test should set json/console loggingvariables when nothing
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
}

exports['Diamorphosis Test should set json/console loggingvariables when console:not set, json:true, styles:[] shoud be console:false, json:true, styles:["json"] 1'] = {
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "debug",
"console": false,
"json": true
Expand Down Expand Up @@ -411,32 +410,31 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
}

exports['Diamorphosis Test should set json/console loggingvariables when console:true, json:true, styles:[] shoud be console:true, json:true, styles:["json"] 1'] = {
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "debug",
"console": true,
"json": true
Expand Down Expand Up @@ -630,32 +628,31 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
}

exports['Diamorphosis Test should set json/console loggingvariables when console:false, json:true, styles:[] shoud be console:false, json:true, styles:["json"] 1'] = {
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "debug",
"console": false,
"json": true
Expand Down Expand Up @@ -849,32 +846,31 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
}

exports['Diamorphosis Test should set json/console loggingvariables when console:not set, json:true, styles:["simple"] shoud be console:false, json:true, styles:["simple"] 1'] = {
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "debug",
"console": false,
"json": true
Expand Down Expand Up @@ -1068,24 +1064,23 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
Expand Down Expand Up @@ -1213,7 +1208,7 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
},
"printLogo": false,
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "fatal",
"console": true,
"json": false
Expand Down Expand Up @@ -1292,24 +1287,23 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
Expand Down Expand Up @@ -1437,7 +1431,7 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
},
"printLogo": false,
"log": {
"pattern": "%[[%d] [%p] %c%] %x{logTracer} %m",
"pattern": "%[[%d] [%p] %c%] %x{requestId}%m %x{logTracer}",
"level": "fatal",
"console": true,
"json": true
Expand Down Expand Up @@ -1518,24 +1512,23 @@ exports['Diamorphosis Test should set json/console loggingvariables when console
"logKeys": [
"requestId",
"visitor",
"correlationId"
"correlationId",
"propagatedHeaders"
],
"istioTraceContextHeaders": {
"propagatedHeaders": {
"enabled": true,
"headers": [
"cf-ray",
"x-request-id",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"x-ot-span-context"
]
},
"headerPropagation": {
"enabled": true,
"headers": [
"cf-ray"
"x-ot-span-context",
"x-depth",
"x-parent-id",
"x-initiator-id"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const nodeVersionGreaterThanEqual = (requestedVersion: string, version =
return true;
};

export function appendHeadersFromStore(properties, store, config) {
export function appendHeadersFromStore(properties: any, store: Map<string, any>, config: any) {
if (!config.requestContext.enabled) return;
if (!config.requestContext.propagatedHeaders.enabled) return;
properties.headers = properties.headers || {};
Expand Down
3 changes: 3 additions & 0 deletions test/examples/json-appender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('json-appender', function () {
message: 'hello world',
context: pickBy({
requestId: 'test-id',
propagatedHeaders: {},
context: 'foo'
})
})
Expand Down Expand Up @@ -78,6 +79,7 @@ describe('json-appender', function () {
message: 'test - this was a test error',
stack_trace: 'Error: test\n at /logError ',
context: pickBy({
propagatedHeaders: {},
requestId: 'test-id',
context: 'foo'
})
Expand All @@ -98,6 +100,7 @@ describe('json-appender', function () {
component: 'koa',
action: '/logError',
params: { path: {}, query: {}, body: {}, requestId: 'test-id' },
propagatedHeaders: {},
state: { riviereStartedAt: 1546300800000, requestId: 'test-id' },
requestId: 'test-id'
},
Expand Down
4 changes: 2 additions & 2 deletions test/examples/request-context-example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('request-context', function () {
describe('when feature flag is off', function () {
beforeEach(function () {
const config = require('../../examples/request-context-example/config.js');
config.requestContext.headerPropagation = { enabled: false };
config.requestContext.propagatedHeaders = { enabled: false };
});

it('should not propagate headers', async function () {
Expand All @@ -118,7 +118,7 @@ describe('request-context', function () {

it('/propagateTracingHeaders returns 200 and propagates whitelisted headers', async function () {
const config = require('../../examples/request-context-example/config.js');
config.requestContext.headerPropagation = { enabled: true, headers: ['header1', 'header2'] };
config.requestContext.propagatedHeaders = { enabled: true, headers: ['header1', 'header2'] };

const propagatedRequestMock = nock('http://foo.com')
.matchHeader('header1', 'header-value')
Expand Down
3 changes: 2 additions & 1 deletion test/initializers/rabbitmq/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('Test rabbitmq connection', function () {
maxRetries: 0,
retryDelay: 1000,
connectDelay: 5000
}
},
requestContext: { enabled: true, propagatedHeaders: { enabled: true } }
};
onStub = sandbox.stub();
stub = sandbox.stub().returns({
Expand Down
Loading

0 comments on commit d19a3dc

Please sign in to comment.