You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds an optional second parameter to the EventBridge.build and StepFunctions.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.
import{EventBridge}from'sls-test-tools'constawsConfig={endpoint: 'http://localhost:4566',region: 'eu-west-1'}// override the default endpoint so that it can be used against localstackconstlocalBus=awaitEventBridge.build('my-local-bus',awsConfig)constawsBus=awaitEventBridge.build('aws-bus')// same as current behaviour
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.
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'constdocClient=newAWSClient.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 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
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.
This PR adds an optional second parameter to the
EventBridge.buildandStepFunctions.buildmethods, 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.