-
Notifications
You must be signed in to change notification settings - Fork 154
tests(idempotency): add utility to workspace unit tests and CI #1160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25d8c48
chore: fix package.lock & package
dreamorosi 5da390e
ci: add idempotency to ci checks on PRs
dreamorosi 2359f65
refactor: minor styling changes to folder structure, exports, types
dreamorosi bcc35b8
test: unit tests style + added missing
dreamorosi 542ec17
chore: temporarily excluded makeFunctionIdempotent from coverage report
dreamorosi fd82383
refactor: rename npx DynamoDbPersistenceLayer to DynamoDBPersistenceL…
dreamorosi 2b53ed8
refactor: rename npx DynamoDbPersistenceLayer to DynamoDBPersistenceL…
dreamorosi c914731
refactor: rename npx DynamoDbPersistenceLayer to DynamoDBPersistenceL…
dreamorosi 7c02087
chore: revert changes to PersistenceLayerInterface
dreamorosi d64cd95
Trigger Build
dreamorosi d66731f
Update packages/idempotency/src/persistence/PersistenceLayer.ts
dreamorosi a0df04f
Merge branch 'main' into refactor/idempotency_tests
dreamorosi d5e6aca
fix: merge conflicts on lock
dreamorosi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,13 @@ | ||
interface ConfigServiceInterface { | ||
|
||
get(name: string): string | ||
|
||
getServiceName(): string | ||
|
||
getFunctionName(): string | ||
|
||
} | ||
|
||
export { | ||
ConfigServiceInterface | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/idempotency/src/config/EnvironmentVariablesService.ts
This file contains hidden or 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,36 @@ | ||
import { ConfigServiceInterface } from './ConfigServiceInterface'; | ||
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons'; | ||
|
||
/** | ||
* Class EnvironmentVariablesService | ||
* | ||
* This class is used to return environment variables that are available in the runtime of | ||
* the current Lambda invocation. | ||
* These variables can be a mix of runtime environment variables set by AWS and | ||
* variables that can be set by the developer additionally. | ||
* | ||
* @class | ||
* @extends {CommonEnvironmentVariablesService} | ||
* @implements {ConfigServiceInterface} | ||
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime | ||
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#environment-variables | ||
*/ | ||
class EnvironmentVariablesService extends CommonEnvironmentVariablesService implements ConfigServiceInterface { | ||
|
||
// Reserved environment variables | ||
private functionNameVariable = 'AWS_LAMBDA_FUNCTION_NAME'; | ||
|
||
/** | ||
* It returns the value of the AWS_LAMBDA_FUNCTION_NAME environment variable. | ||
* | ||
* @returns {string} | ||
*/ | ||
public getFunctionName(): string { | ||
return this.get(this.functionNameVariable); | ||
} | ||
|
||
} | ||
|
||
export { | ||
EnvironmentVariablesService | ||
}; |
This file contains hidden or 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 @@ | ||
export * from './EnvironmentVariablesService'; |
This file contains hidden or 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,10 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { AnyFunction } from './types/AnyFunction'; | ||
import { IdempotencyOptions } from './IdempotencyOptions'; | ||
import type { AnyFunction } from './types/AnyFunction'; | ||
import type { IdempotencyOptions } from './types/IdempotencyOptions'; | ||
|
||
const makeFunctionIdempotent = <U>( | ||
fn: AnyFunction<U>, | ||
_options: IdempotencyOptions | ||
// TODO: revisit this with a more specific type if possible | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
): (...args: Array<any>) => Promise<U | void> => (...args) => fn(...args); | ||
|
||
export { makeFunctionIdempotent }; |
This file contains hidden or 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 hidden or 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
3 changes: 2 additions & 1 deletion
3
packages/idempotency/src/persistence/PersistenceLayerInterface.ts
This file contains hidden or 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 hidden or 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,4 @@ | ||
export * from './DynamoDbPersistenceLayer'; | ||
export * from './DynamoDBPersistenceLayer'; | ||
export * from './PersistenceLayer'; | ||
export * from './PersistenceLayerInterface'; | ||
export * from './IdempotencyRecord'; |
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ges/idempotency/src/IdempotencyOptions.ts → ...empotency/src/types/IdempotencyOptions.ts
This file contains hidden or 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 hidden or 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,7 @@ | ||
type PersistenceLayerConfigureOptions = { | ||
functionName?: string | ||
}; | ||
|
||
export { | ||
PersistenceLayerConfigureOptions | ||
}; |
This file contains hidden or 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,2 +1,3 @@ | ||
export * from './AnyFunction'; | ||
export * from './IdempotencyRecordStatus'; | ||
export * from './IdempotencyRecordStatus'; | ||
export * from './PersistenceLayer'; |
7 changes: 6 additions & 1 deletion
7
packages/idempotency/tests/helpers/populateEnvironmentVariables.ts
This file contains hidden or 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,2 +1,7 @@ | ||
// Reserved variables | ||
process.env.AWS_REGION = 'us-east-1'; | ||
process.env._X_AMZN_TRACE_ID = '1-abcdef12-3456abcdef123456abcdef12'; | ||
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-lambda-function'; | ||
process.env.AWS_EXECUTION_ENV = 'nodejs16.x'; | ||
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '128'; | ||
process.env.AWS_REGION = 'eu-west-1'; | ||
process.env._HANDLER = 'index.handler'; | ||
34 changes: 0 additions & 34 deletions
34
packages/idempotency/tests/unit/EnvironmentVariableService.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question) Do we really need all of these env vars? Wouldn't only
AWS_LAMBDA_FUNCTION_NAME
be enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use only the name at the moment, and we'll be using also the region in the e2e tests.
I have added them mostly for consistency so that all the unit tests in the repo have the same environment. Mostly for cognitive load.
What do you think?