Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
[pull_request]

name: Check

on:
pull_request:

jobs:
check:
name: Run Unit Tests
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint

on:
pull_request:

jobs:
lint:
name: Run Linter
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Run eslint
run: |
npm ci
npm run lint
2 changes: 1 addition & 1 deletion __tests__/deep_equal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Deep Equal Tests', () => {
});

test('Handle lambda function configuration objects', () => {
const lambdaConfig1 = {
const lambdaConfig1 = {
FunctionName: 'test-function',
Runtime: 'nodejs18.x',
MemorySize: 512,
Expand Down
3 changes: 1 addition & 2 deletions __tests__/function_create.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs/promises');
const path = require('path');
const core = require('@actions/core');
const { LambdaClient, GetFunctionConfigurationCommand, CreateFunctionCommand, UpdateFunctionCodeCommand, GetFunctionCommand} = require('@aws-sdk/client-lambda');
const { LambdaClient, GetFunctionConfigurationCommand, CreateFunctionCommand } = require('@aws-sdk/client-lambda');
const index = require('../index');
const { checkFunctionExists } = index;

Expand Down
2 changes: 1 addition & 1 deletion __tests__/has_configuration_changed.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const core = require('@actions/core');
const { isEmptyValue, cleanNullKeys, hasConfigurationChanged, deepEqual } = require('../index');
const { isEmptyValue, cleanNullKeys, hasConfigurationChanged } = require('../index');

jest.mock('@actions/core');

Expand Down
3 changes: 1 addition & 2 deletions __tests__/package_artifacts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ describe('Package Artifacts Tests', () => {

test('should handle error during directory cleanup', async () => {

const expectedTempDir = '/mock/tmp/lambda-temp-1234567890';
const expectedZipPath = '/mock/tmp/lambda-function-1234567890.zip';

const rmError = new Error('Failed to remove directory');
Expand Down Expand Up @@ -212,7 +211,7 @@ describe('Package Artifacts Tests', () => {

test('should handle error during file copying', async () => {

fs.cp.mockImplementation((src, dest, options) => {
fs.cp.mockImplementation((src, _dest, _options) => {
if (src.includes('file1.js')) {
return Promise.reject(new Error('Failed to copy file'));
}
Expand Down
19 changes: 7 additions & 12 deletions __tests__/s3_bucket_operations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,13 @@ describe('S3 Bucket Operations Tests', () => {

jest.spyOn(mainModule, 'createBucket').mockResolvedValue(true);
mockS3Send.mockResolvedValueOnce({});
try {
await mainModule.uploadToS3(
'/path/to/deployment.zip',
'new-bucket',
'lambda/function.zip',
'us-east-1',
'123456789012'
);
} catch (error) {
throw error;
}
await mainModule.uploadToS3(
'/path/to/deployment.zip',
'new-bucket',
'lambda/function.zip',
'us-east-1',
'123456789012'
);
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('Bucket new-bucket does not exist. Attempting to create it'));
expect(mockS3Send).toHaveBeenCalledWith(expect.any(PutObjectCommand));
});
Expand Down Expand Up @@ -649,7 +645,6 @@ describe('S3 Bucket Operations Tests', () => {

mainModule.uploadToS3.mockReset();

const functionName = core.getInput('function-name');
const s3Bucket = core.getInput('s3-bucket');
if (s3Bucket) {
await mainModule.uploadToS3('file.zip', s3Bucket, 'key.zip', 'region');
Expand Down
5 changes: 0 additions & 5 deletions __tests__/update_function_code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ describe('Lambda Function Code Tests', () => {
const originalUpdateFunctionCode = index.updateFunctionCode;

index.updateFunctionCode = jest.fn().mockImplementation(async (client, params) => {
const s3Result = {
bucket: params.s3Bucket,
key: params.s3Key
};

const command = new UpdateFunctionCodeCommand({
FunctionName: params.functionName,
S3Bucket: params.s3Bucket,
Expand Down
70 changes: 35 additions & 35 deletions __tests__/validations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ describe('Validations Tests', () => {
test('should handle empty memory size input', () => {
jest.clearAllMocks();
core.getInput.mockImplementation((name) => {
if (name === 'memory-size') return '';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
if (name === 'memory-size') return '';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
});
const result = originalValidations.validateAllInputs();
Expand All @@ -56,12 +56,12 @@ describe('Validations Tests', () => {
test('should handle non-numeric memory size input', () => {
jest.clearAllMocks();
core.getInput.mockImplementation((name) => {
if (name === 'memory-size') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
if (name === 'memory-size') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
});
const result = originalValidations.validateAllInputs();
Expand Down Expand Up @@ -93,13 +93,13 @@ describe('Validations Tests', () => {
test('should handle non-numeric memory size input', () => {
jest.clearAllMocks();
core.getInput.mockImplementation((name) => {
if (name === 'timeout') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
if (name === 'timeout') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
});
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
Expand Down Expand Up @@ -130,13 +130,13 @@ describe('Validations Tests', () => {
test('should handle non-numeric memory size input', () => {
jest.clearAllMocks();
core.getInput.mockImplementation((name) => {
if (name === 'ephemeral-storage') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
if (name === 'ephemeral-storage') return 'hello';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
if (name === 'handler') return 'index.handler';
if (name === 'runtime') return 'nodejs18.x';
return '';
});
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('Validations Tests', () => {
test('should reject invalid source KMS key ARN format', () => {
core.getInput.mockImplementation((name) => {
if (name === 'kms-key-arn') return 'invalid:kms:key:arn';
if (name === 'source-kms-key-arn') return 'invalid:kms:key:arn'
if (name === 'source-kms-key-arn') return 'invalid:kms:key:arn';
if (name === 'function-name') return 'test-function';
if (name === 'region') return 'us-east-1';
if (name === 'code-artifacts-dir') return './artifacts';
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('Validations Tests', () => {
test('should accept valid environment variables', () => {
const mockGetInput = jest.fn((name) => {
if (name === 'environment') {
return '{"ENV":"prod","DEBUG":"true","API_URL":"https://api.example.com"}'
return '{"ENV":"prod","DEBUG":"true","API_URL":"https://api.example.com"}';
}
const inputs = {
'function-name': 'test-function',
Expand Down Expand Up @@ -889,7 +889,7 @@ describe('Validations Tests', () => {
describe('VPC Configuration Edge Cases', () => {
test('should reject vpc-config with malformed SubnetIds', () => {
const invalidVpcConfig = JSON.stringify({
SubnetIds: "subnet-123",
SubnetIds: 'subnet-123',
SecurityGroupIds: ['sg-123']
});
core.getInput.mockImplementation((name) => {
Expand All @@ -906,7 +906,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("vpc-config must include 'SubnetIds' as an array")
expect.stringContaining('vpc-config must include \'SubnetIds\' as an array')
);
});
test('should reject vpc-config with empty SecurityGroupIds array', () => {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("tracing-config Mode must be 'Active' or 'PassThrough'")
expect.stringContaining('tracing-config Mode must be \'Active\' or \'PassThrough\'')
);
});
});
Expand Down Expand Up @@ -1057,7 +1057,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("snap-start ApplyOn must be 'PublishedVersions' or 'None'")
expect.stringContaining('snap-start ApplyOn must be \'PublishedVersions\' or \'None\'')
);
});
});
Expand All @@ -1077,7 +1077,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("file-system-configs must be an array")
expect.stringContaining('file-system-configs must be an array')
);
});
test('should reject file-system-configs with missing Arn', () => {
Expand All @@ -1096,7 +1096,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("Each file-system-config must include 'Arn' and 'LocalMountPath'")
expect.stringContaining('Each file-system-config must include \'Arn\' and \'LocalMountPath\'')
);
});
test('should validate multiple file system configs', () => {
Expand Down Expand Up @@ -1154,7 +1154,7 @@ describe('Validations Tests', () => {
const result = originalValidations.validateAllInputs();
expect(result.valid).toBe(false);
expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("tags must be an object of key-value pairs")
expect.stringContaining('tags must be an object of key-value pairs')
);
});
});
Expand Down
Loading
Loading