Skip to content

Commit 68ba692

Browse files
author
Niko Lehtovirta
authored
fix: Endpoints from args and config are combined (#6)
1 parent b731b94 commit 68ba692

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/lib/monitoring/config.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,44 @@ test('add endpoint', async t => {
5151
await conf.setPagerDutyEndpoint(args);
5252
t.is(conf.getConfig().custom.snsTopic?.critical?.endpoints?.length, 1);
5353
});
54+
55+
test('Combine earlier endpoints', async t => {
56+
const args = {
57+
config: 'test',
58+
service: ['lambda'],
59+
stage: 'dev',
60+
endpoints: ['https://events.pagerduty.com/integration/abcb/enqueue'],
61+
include: [],
62+
exclude: [],
63+
dry: true,
64+
verbose: false,
65+
};
66+
const conf = new config.ConfigGenerator(args);
67+
await conf.setPagerDutyEndpoint(args);
68+
69+
// Add second endpoint
70+
args.endpoints = ['https://events.pagerduty.com/integration/abcb/enqueue2'];
71+
await conf.setPagerDutyEndpoint(args);
72+
73+
t.is(conf.getConfig().custom.snsTopic?.critical?.endpoints?.length, 2);
74+
});
75+
76+
test('Combine earlier endpoints should filter out same endpoints', async t => {
77+
const args = {
78+
config: 'test',
79+
service: ['lambda'],
80+
stage: 'dev',
81+
endpoints: ['https://events.pagerduty.com/integration/abcb/enqueue'],
82+
include: [],
83+
exclude: [],
84+
dry: true,
85+
verbose: false,
86+
};
87+
const conf = new config.ConfigGenerator(args);
88+
await conf.setPagerDutyEndpoint(args);
89+
90+
// Add same endpoints again
91+
await conf.setPagerDutyEndpoint(args);
92+
93+
t.is(conf.getConfig().custom.snsTopic?.critical?.endpoints?.length, 1);
94+
});

src/lib/monitoring/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class ConfigGenerator {
9090
);
9191
const newTopic = {
9292
...topic,
93-
endpoints: endpoints.filter(e => e) as string[],
93+
endpoints: [...new Set([...(topic.endpoints || []), ...endpoints].filter(e => e))] as string[],
9494
};
9595
return [topicKey, newTopic];
9696
}),

0 commit comments

Comments
 (0)