Open smbkr opened 2 years ago
Another option is to add an --endpoint=
CLI flag like with the region and stack ones, and then in the implementation anywhere new AWSClient.SomeAWSService()
is called, pass in the endpoint. This would be similar to the current implementation of src/assertions/toContainItemWithValues/index.ts:11
which does the same with region.
Usage would be something like:
jest '--region=eu-west-1' '--endpoint=http://localhost:4566' --runInBand
and in the implementation, something like:
import { region, endpoint } from '../../helpers/general'
const docClient = new AWSClient.DynamoDB.DocumentClient({
region, // this is in the current implementation but is not actually required as the region is set globally in `helpers/general.ts`
endpoint,
});
One problem with the current approach is that it only applies to the EventBridge
and StepFunctions
helpers. This CLI flag alternative would allow configuring the endpoint for all AWS services, including e.g. the S3 client used in the S3 assertions, the DynamoDB assertions, etc. And I find it a bit more consistent with the existing configuration options.
Thoughts?
This PR adds an optional second parameter to the
EventBridge.build
andStepFunctions.build
methods, which allows the caller to specify AWS service client configuration. This permits a user to override the default endpoint, timeout, specify a logger, etc.The behaviour when no client config is specified is the same as the current behaviour.
Closes #31
Usage example:
The use case for myself is to allow overriding the endpoint as shown above so tests can run against localstack. This will also open up the possibility of writing tests for the library itself using localstack if desired.