forked from philips-labs/terraform-aws-github-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(syncer): Add tests, coverage report, and refactor lambda / naming (…
…philips-labs#1478) * fix: Add tests, coverage report, and refactor lambda / naming * fix: Add tests, coverage report, and refactor lambda / naming
- Loading branch information
Showing
9 changed files
with
360 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/**/*.{ts,js,jsx}', '!src/**/*local*.ts'], | ||
coverageThreshold: { | ||
global: { | ||
branches: 80, | ||
functions: 60, | ||
lines: 80, | ||
statements: 80 | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/lambda.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { sync } from './syncer/syncer'; | ||
import { handler } from './lambda'; | ||
import { mocked } from 'ts-jest/utils'; | ||
|
||
jest.mock('./syncer/syncer'); | ||
|
||
describe('Test scale up lambda wrapper.', () => { | ||
it('Scale without error should resolve.', async () => { | ||
const mock = mocked(sync); | ||
mock.mockImplementation(() => { | ||
return new Promise((resolve) => { | ||
resolve(); | ||
}); | ||
}); | ||
await expect(handler({}, {})).resolves; | ||
}); | ||
|
||
it('Scale without error should resolve2 . ', async () => { | ||
const mock = mocked(sync); | ||
mock.mockRejectedValue(new Error('')); | ||
|
||
await expect(handler({}, {})).resolves; | ||
}); | ||
}); |
19 changes: 11 additions & 8 deletions
19
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/lambda.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { handle } from './syncer/handler'; | ||
import { sync } from './syncer/syncer'; | ||
import { logger } from './syncer/logger'; | ||
|
||
// eslint-disable-next-line | ||
export const handler = async (event: any, context: any, callback: any): Promise<void> => { | ||
export const handler = async (event: any, context: any): Promise<void> => { | ||
logger.setSettings({ requestId: context.awsRequestId }); | ||
logger.debug(JSON.stringify(event)); | ||
try { | ||
await handle(); | ||
callback(null); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
|
||
return new Promise((resolve) => { | ||
sync() | ||
.then(() => resolve()) | ||
.catch((e: Error) => { | ||
logger.warn('Ignoring error:', e); | ||
resolve(); | ||
}); | ||
}); | ||
}; |
4 changes: 2 additions & 2 deletions
4
modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/local.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.