Skip to content

Commit

Permalink
Fix generic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Oct 22, 2020
1 parent b58563d commit 9d0f942
Showing 1 changed file with 127 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,154 +15,174 @@ describe('Generic Rules', () => {
describe('configurable message rules', () => {
test('includes the event.dataset and log.level if present', () => {
const flattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
'event.dataset': 'generic.test',
'log.level': 'TEST_LEVEL',
first_generic_message: 'TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
'event.dataset': ['generic.test'],
'log.level': ['TEST_LEVEL'],
first_generic_message: ['TEST_MESSAGE'],
};
const highlights = {
first_generic_message: ['TEST'],
};

expect(format(flattenedDocument, highlights)).toMatchInlineSnapshot(`
Array [
Object {
"constant": "[",
},
Object {
"field": "event.dataset",
"highlights": Array [],
"value": "generic.test",
},
Object {
"constant": "][",
},
Object {
"field": "log.level",
"highlights": Array [],
"value": "TEST_LEVEL",
},
Object {
"constant": "] ",
},
Object {
"field": "first_generic_message",
"highlights": Array [
"TEST",
],
"value": "TEST_MESSAGE",
},
]
`);
Array [
Object {
"constant": "[",
},
Object {
"field": "event.dataset",
"highlights": Array [],
"value": Array [
"generic.test",
],
},
Object {
"constant": "][",
},
Object {
"field": "log.level",
"highlights": Array [],
"value": Array [
"TEST_LEVEL",
],
},
Object {
"constant": "] ",
},
Object {
"field": "first_generic_message",
"highlights": Array [
"TEST",
],
"value": Array [
"TEST_MESSAGE",
],
},
]
`);
});

test('includes the log.level if present', () => {
const flattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
'log.level': 'TEST_LEVEL',
first_generic_message: 'TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
'log.level': ['TEST_LEVEL'],
first_generic_message: ['TEST_MESSAGE'],
};

expect(format(flattenedDocument, {})).toMatchInlineSnapshot(`
Array [
Object {
"constant": "[",
},
Object {
"field": "log.level",
"highlights": Array [],
"value": "TEST_LEVEL",
},
Object {
"constant": "] ",
},
Object {
"field": "first_generic_message",
"highlights": Array [],
"value": "TEST_MESSAGE",
},
]
`);
Array [
Object {
"constant": "[",
},
Object {
"field": "log.level",
"highlights": Array [],
"value": Array [
"TEST_LEVEL",
],
},
Object {
"constant": "] ",
},
Object {
"field": "first_generic_message",
"highlights": Array [],
"value": Array [
"TEST_MESSAGE",
],
},
]
`);
});

test('includes the message', () => {
const firstFlattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
first_generic_message: 'FIRST_TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
first_generic_message: ['FIRST_TEST_MESSAGE'],
};

expect(format(firstFlattenedDocument, {})).toMatchInlineSnapshot(`
Array [
Object {
"field": "first_generic_message",
"highlights": Array [],
"value": "FIRST_TEST_MESSAGE",
},
]
`);
Array [
Object {
"field": "first_generic_message",
"highlights": Array [],
"value": Array [
"FIRST_TEST_MESSAGE",
],
},
]
`);

const secondFlattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
second_generic_message: 'SECOND_TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
second_generic_message: ['SECOND_TEST_MESSAGE'],
};

expect(format(secondFlattenedDocument, {})).toMatchInlineSnapshot(`
Array [
Object {
"field": "second_generic_message",
"highlights": Array [],
"value": "SECOND_TEST_MESSAGE",
},
]
`);
Array [
Object {
"field": "second_generic_message",
"highlights": Array [],
"value": Array [
"SECOND_TEST_MESSAGE",
],
},
]
`);
});
});

describe('log.original fallback', () => {
test('includes the event.dataset if present', () => {
const flattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
'event.dataset': 'generic.test',
'log.original': 'TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
'event.dataset': ['generic.test'],
'log.original': ['TEST_MESSAGE'],
};

expect(format(flattenedDocument, {})).toMatchInlineSnapshot(`
Array [
Object {
"constant": "[",
},
Object {
"field": "event.dataset",
"highlights": Array [],
"value": "generic.test",
},
Object {
"constant": "] ",
},
Object {
"field": "log.original",
"highlights": Array [],
"value": "TEST_MESSAGE",
},
]
`);
Array [
Object {
"constant": "[",
},
Object {
"field": "event.dataset",
"highlights": Array [],
"value": Array [
"generic.test",
],
},
Object {
"constant": "] ",
},
Object {
"field": "log.original",
"highlights": Array [],
"value": Array [
"TEST_MESSAGE",
],
},
]
`);
});

test('includes the original message', () => {
const flattenedDocument = {
'@timestamp': '2016-12-26T16:22:13.000Z',
'log.original': 'TEST_MESSAGE',
'@timestamp': ['2016-12-26T16:22:13.000Z'],
'log.original': ['TEST_MESSAGE'],
};

expect(format(flattenedDocument, {})).toMatchInlineSnapshot(`
Array [
Object {
"field": "log.original",
"highlights": Array [],
"value": "TEST_MESSAGE",
},
]
`);
Array [
Object {
"field": "log.original",
"highlights": Array [],
"value": Array [
"TEST_MESSAGE",
],
},
]
`);
});
});
});

0 comments on commit 9d0f942

Please sign in to comment.