-
Notifications
You must be signed in to change notification settings - Fork 156
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
Changes from 10 commits
25d8c48
5da390e
2359f65
bcc35b8
542ec17
fd82383
2b53ed8
c914731
7c02087
d64cd95
d66731f
a0df04f
d5e6aca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
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 | ||
}; |
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 | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './EnvironmentVariablesService'; |
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 }; |
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'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type PersistenceLayerConfigureOptions = { | ||
functionName?: string | ||
}; | ||
|
||
export { | ||
PersistenceLayerConfigureOptions | ||
}; |
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'; |
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'; | ||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.