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
define resources and return outputs needed later like arns
consumes said outputs and make calls via clients bound using test credentials.
Test the output of api calls
Current Example Test (eventbus.localstack.test.ts):
testResource("Bus event starts step function and writes to dynamo",(parent,role)=>{constaddr=newCfnOutput(parent,"out",{value: ""});constbus=newEventBus<Event<{id: string},"test">>(parent,"bus",{eventBusName: addr.node.addr,});consttable=Table.fromTable<{id: string},"id">(newaws_dynamodb.Table(parent,"table",{tableName: addr.node.addr+"table",partitionKey: {name: "id",type: aws_dynamodb.AttributeType.STRING,},}));constputMachine=newStepFunction<{id: string},void>(parent,"machine",async(event)=>{await$AWS.DynamoDB.PutItem({Item: {id: {S: event.id},},Table: table,});});bus.resource.grantPutEventsTo(role);table.resource.grantReadData(role);bus.when(parent,"rule",(event)=>event.source==="test").map((event)=>event.detail).pipe(putMachine);return{outputs: {bus: addr.node.addr,table: addr.node.addr+"table",},};},async(context,clients)=>{constid=`${context.bus}${Math.floor(Math.random()*1000000)}`;awaitclients.eventBridge.putEvents({Entries: [{EventBusName: context.bus,Source: "test",Detail: JSON.stringify({
id,}),DetailType: "someType",},],}).promise();// Give time for the event to make it to dynamo. Localstack is pretty slow.// 1 - 1s// 2 - 2s// 3 - 4s// 4 - 8s// 5 - 16sconstitem=awaitretry(()=>clients.dynamoDB.getItem({Key: {id: {S: id},},TableName: context.table,ConsistentRead: true,}).promise(),(item)=>!!item.Item,5,10000,2);expect(item.Item).toBeDefined();});
Notice that we need to build the client, grant permissions, and inject the outputs of the stack. This is very similar to how a Functionless Function works already, but the Function uses ENV variables to inject in deployment time values (arns, names, etc).
Currently our tests follow the pattern:
Current Example Test (eventbus.localstack.test.ts):
Notice that we need to build the client, grant permissions, and inject the outputs of the stack. This is very similar to how a Functionless
Function
works already, but theFunction
uses ENV variables to inject in deployment time values (arns, names, etc).We should support something like
Which would turn the above test into
The text was updated successfully, but these errors were encountered: