Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ersin-erdal committed Jan 2, 2025
1 parent dae22c8 commit e6ae446
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ const getIndexTemplatePutBody = (opts?: GetIndexTemplatePutBodyOpts) => {

const indexPatterns = useDataStream
? [`.alerts-${context ? context : 'test'}.alerts-${namespace}`]
: [`.internal.alerts-${context ? context : 'test'}.alerts-${namespace}-*`];
: [
`.internal.alerts-${context ? context : 'test'}.alerts-${namespace}-*`,
`.reindexed-v8-internal.alerts-${context ? context : 'test'}.alerts-${namespace}-*`,
];
return {
name: `.alerts-${context ? context : 'test'}.alerts-${namespace}-index-template`,
body: {
Expand Down Expand Up @@ -564,7 +567,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenCalledWith({
index: '.internal.alerts-test.alerts-default-*',
index: [
'.internal.alerts-test.alerts-default-*',
`.reindexed-v8-internal.alerts-test.alerts-default-*`,
],
name: '.alerts-test.alerts-*',
});
}
Expand Down Expand Up @@ -627,7 +633,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenCalledWith({
index: '.internal.alerts-test.alerts-default-*',
index: [
'.internal.alerts-test.alerts-default-*',
`.reindexed-v8-internal.alerts-test.alerts-default-*`,
],
name: '.alerts-test.alerts-*',
});
}
Expand Down Expand Up @@ -686,7 +695,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenCalledWith({
index: '.internal.alerts-test.alerts-default-*',
index: [
'.internal.alerts-test.alerts-default-*',
`.reindexed-v8-internal.alerts-test.alerts-default-*`,
],
name: '.alerts-test.alerts-*',
});
}
Expand Down Expand Up @@ -728,7 +740,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenNthCalledWith(1, {
index: '.internal.alerts-test.alerts-default-*',
index: [
'.internal.alerts-test.alerts-default-*',
`.reindexed-v8-internal.alerts-test.alerts-default-*`,
],
name: '.alerts-test.alerts-*',
});
}
Expand Down Expand Up @@ -792,7 +807,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenNthCalledWith(2, {
index: '.internal.alerts-test.alerts-another-namespace-*',
index: [
'.internal.alerts-test.alerts-another-namespace-*',
'.reindexed-v8-internal.alerts-test.alerts-another-namespace-*',
],
name: '.alerts-test.alerts-*',
});
}
Expand Down Expand Up @@ -826,7 +844,10 @@ describe('Alerts Service', () => {
})
);
expect(clusterClient.indices.getAlias).toHaveBeenCalledWith({
index: '.internal.alerts-test.alerts-default-*',
index: [
'.internal.alerts-test.alerts-default-*',
'.reindexed-v8-internal.alerts-test.alerts-default-*',
],
name: '.alerts-test.alerts-*',
});
expect(clusterClient.indices.putSettings).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -871,11 +892,12 @@ describe('Alerts Service', () => {
const template = {
name: `.alerts-empty.alerts-default-index-template`,
body: {
index_patterns: [
useDataStreamForAlerts
? `.alerts-empty.alerts-default`
: `.internal.alerts-empty.alerts-default-*`,
],
index_patterns: useDataStreamForAlerts
? [`.alerts-empty.alerts-default`]
: [
`.internal.alerts-empty.alerts-default-*`,
`.reindexed-v8-internal.alerts-empty.alerts-default-*`,
],
composed_of: ['.alerts-framework-mappings'],
...(useDataStreamForAlerts ? { data_stream: { hidden: true } } : {}),
priority: 7,
Expand Down Expand Up @@ -931,7 +953,10 @@ describe('Alerts Service', () => {
},
});
expect(clusterClient.indices.getAlias).toHaveBeenCalledWith({
index: '.internal.alerts-empty.alerts-default-*',
index: [
'.internal.alerts-empty.alerts-default-*',
'.reindexed-v8-internal.alerts-empty.alerts-default-*',
],
name: '.alerts-empty.alerts-*',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ describe('getIndexTemplateAndPattern', () => {
expect(getIndexTemplateAndPattern({ context: 'test' })).toEqual({
template: '.alerts-test.alerts-default-index-template',
pattern: '.internal.alerts-test.alerts-default-*',
reindexedPattern: '.reindexed-v8-internal.alerts-test.alerts-default-*',
basePattern: '.alerts-test.alerts-*',
alias: '.alerts-test.alerts-default',
validPrefixes: [
'.ds-.alerts-',
'.internal.alerts-',
'.alerts-',
'.internal.preview.alerts-',
'.internal.alerts-',
'.reindexed-v8-internal.alerts-',
'.preview.alerts-',
'.internal.preview.alerts-',
'.reindexed-v8-internal.preview.alerts-',
],
name: '.internal.alerts-test.alerts-default-000001',
});
Expand All @@ -53,14 +56,17 @@ describe('getIndexTemplateAndPattern', () => {
expect(getIndexTemplateAndPattern({ context: 'test', namespace: 'special' })).toEqual({
template: '.alerts-test.alerts-special-index-template',
pattern: '.internal.alerts-test.alerts-special-*',
reindexedPattern: '.reindexed-v8-internal.alerts-test.alerts-special-*',
basePattern: '.alerts-test.alerts-*',
alias: '.alerts-test.alerts-special',
validPrefixes: [
'.ds-.alerts-',
'.internal.alerts-',
'.alerts-',
'.internal.preview.alerts-',
'.internal.alerts-',
'.reindexed-v8-internal.alerts-',
'.preview.alerts-',
'.internal.preview.alerts-',
'.reindexed-v8-internal.preview.alerts-',
],
name: '.internal.alerts-test.alerts-special-000001',
});
Expand All @@ -76,15 +82,18 @@ describe('getIndexTemplateAndPattern', () => {
).toEqual({
template: '.alerts-test.alerts-special-index-template',
pattern: '.internal.alerts-test.alerts-special-*',
reindexedPattern: '.reindexed-v8-internal.alerts-test.alerts-special-*',
basePattern: '.alerts-test.alerts-*',
alias: '.alerts-test.alerts-special',
name: '.internal.alerts-test.alerts-special-000001',
validPrefixes: [
'.ds-.alerts-',
'.internal.alerts-',
'.alerts-',
'.internal.preview.alerts-',
'.internal.alerts-',
'.reindexed-v8-internal.alerts-',
'.preview.alerts-',
'.internal.preview.alerts-',
'.reindexed-v8-internal.preview.alerts-',
],
secondaryAlias: `siem.signals-special`,
});
Expand Down

0 comments on commit e6ae446

Please sign in to comment.