Skip to content

Commit

Permalink
rename entry points lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Oct 17, 2024
1 parent 6649aa9 commit bd15fc9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lambdas/functions/webhook/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const config: Config = {
...defaultConfig,
coverageThreshold: {
global: {
statements: 99.2,
statements: 99.58,
branches: 100,
functions: 100,
lines: 99.25,
lines: 99.57,
},
},
};
Expand Down
8 changes: 4 additions & 4 deletions lambdas/functions/webhook/src/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { APIGatewayEvent, Context } from 'aws-lambda';
import { mocked } from 'jest-mock';
import { WorkflowJobEvent } from '@octokit/webhooks-types';

import { dispatchToRunners, eventBridgeWebhook, githubWebhook } from './lambda';
import { dispatchToRunners, eventBridgeWebhook, directWebhook } from './lambda';
import { handle, publishOnEventBridge } from './webhook';
import ValidationError from './ValidationError';
import { getParameter } from '@aws-github-runner/aws-ssm-util';
Expand Down Expand Up @@ -98,23 +98,23 @@ describe('Test webhook lambda wrapper.', () => {
});
});

const result = await githubWebhook(event, context);
const result = await directWebhook(event, context);
expect(result).toEqual({ body: 'test', statusCode: 200 });
});

it('An expected error, resolve.', async () => {
const mock = mocked(handle);
mock.mockRejectedValue(new ValidationError(400, 'some error'));

const result = await githubWebhook(event, context);
const result = await directWebhook(event, context);
expect(result).toMatchObject({ body: 'some error', statusCode: 400 });
});

it('Errors are not thrown.', async () => {
const mock = mocked(handle);
const logSpy = jest.spyOn(logger, 'error');
mock.mockRejectedValue(new Error('some error'));
const result = await githubWebhook(event, context);
const result = await directWebhook(event, context);
expect(result).toMatchObject({ body: 'Check the Lambda logs for the error details.', statusCode: 500 });
expect(logSpy).toHaveBeenCalledTimes(1);
});
Expand Down
4 changes: 2 additions & 2 deletions lambdas/functions/webhook/src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface Response {
body: string;
}

middy(githubWebhook).use(captureLambdaHandler(tracer));
middy(directWebhook).use(captureLambdaHandler(tracer));

export async function githubWebhook(event: APIGatewayEvent, context: Context): Promise<Response> {
export async function directWebhook(event: APIGatewayEvent, context: Context): Promise<Response> {
setContext(context, 'lambda.ts');
logger.logEventIfEnabled(event);

Expand Down
2 changes: 1 addition & 1 deletion modules/webhook/direct/webhook.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "aws_lambda_function" "webhook" {
source_code_hash = var.config.lambda_s3_bucket == null ? filebase64sha256(local.lambda_zip) : null
function_name = "${var.config.prefix}-webhook"
role = aws_iam_role.webhook_lambda.arn
handler = "index.githubWebhook"
handler = "index.directWebhook"
runtime = var.config.lambda_runtime
memory_size = var.config.lambda_memory_size
timeout = var.config.lambda_timeout
Expand Down

0 comments on commit bd15fc9

Please sign in to comment.