Skip to content

Commit 9cff596

Browse files
committed
add tests
1 parent cabcb69 commit 9cff596

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

lambdas/functions/webhook/src/ConfigLoader.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class ConfigWebhook extends BaseConfig {
9292
this.loadParameter(process.env.PARAMETER_RUNNER_MATCHER_CONFIG_PATH, 'matcherConfig'),
9393
this.loadParameter(process.env.PARAMETER_GITHUB_APP_WEBHOOK_SECRET, 'webhookSecret'),
9494
]);
95+
96+
validateWebhookSecret(this);
97+
validateRunnerMatcherConfig(this);
9598
}
9699
}
97100

@@ -104,6 +107,9 @@ export class ConfigWebhookEventBridge extends BaseConfig {
104107
this.loadEnvVar(process.env.ALLOWED_EVENTS, 'allowedEvents', []);
105108
this.loadEnvVar(process.env.EVENT_BUS_NAME, 'eventBusName');
106109
await this.loadParameter(process.env.PARAMETER_GITHUB_APP_WEBHOOK_SECRET, 'webhookSecret');
110+
111+
validateEventBusName(this);
112+
validateWebhookSecret(this);
107113
}
108114
}
109115

@@ -116,9 +122,24 @@ export class ConfigDispatcher extends BaseConfig {
116122
this.loadEnvVar(process.env.REPOSITORY_ALLOW_LIST, 'repositoryAllowList', []);
117123
await this.loadParameter(process.env.PARAMETER_RUNNER_MATCHER_CONFIG_PATH, 'matcherConfig');
118124

119-
// check matcherConfig object is not empty
120-
if (this.matcherConfig.length === 0) {
121-
this.configLoadingErrors.push('Matcher config is empty');
122-
}
125+
validateRunnerMatcherConfig(this);
126+
}
127+
}
128+
129+
function validateEventBusName(config: ConfigWebhookEventBridge): void {
130+
if (!config.eventBusName) {
131+
config.configLoadingErrors.push('Environment variable for eventBusName is not set and no default value provided.');
132+
}
133+
}
134+
135+
function validateWebhookSecret(config: ConfigWebhookEventBridge | ConfigWebhook): void {
136+
if (!config.webhookSecret) {
137+
config.configLoadingErrors.push('Environment variable for webhookSecret is not set and no default value provided.');
138+
}
139+
}
140+
141+
function validateRunnerMatcherConfig(config: ConfigDispatcher | ConfigWebhook): void {
142+
if (config.matcherConfig.length === 0) {
143+
config.configLoadingErrors.push('Matcher config is empty');
123144
}
124145
}

0 commit comments

Comments
 (0)