Developer guide for making Integration Tests: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Overview =") |
No edit summary |
||
Line 1: | Line 1: | ||
= Overview = | = Overview = | ||
= Setup integrationtest = | |||
=== Step 1; Create object in bucket === | |||
# Create your folder in bucket '''integrationtest-config-us-east-2/test_config/{<u>your folder name</u>}''' in S3 bucket | |||
#* '''{<u>your folder name</u>}''' maybe is your nickname eg. jamesDev, nicoleDev | |||
#* Can create a subfolder in your folder for each test case or service that you want to test | |||
#:: eg. - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager | |||
#::: - integrationtest-config-us-east-2/test_config/jamesDev/ProcessLogical | |||
#::: - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/ProcessLogical | |||
# Create a file in a folder that is used for testing | |||
#* ''resources.json / events.json / tests.json'' | |||
#* '''resources.json''' and '''events.json''' is json object | |||
#* '''tests.json''' is json array of objects | |||
#* Can create these files in a SharedResource folder and share it with another test for collaborative usage | |||
#:: eg. integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/SharedResource/resources.json | |||
#* In the main prefix for testing, you don’t need to upload every file. If you have a file in SharedResource, you can skip uploading it | |||
## '''resources.json''' | |||
##* Have 2 main object keys is ''Lambda'' and ''Dynamodb'' | |||
##:<syntaxhighlight lang="JavaScript"> | |||
{ | |||
"Lambda":{ | |||
"{FunctionNameHdrSqs}":{ | |||
"localLacation":"/src/FunctionNameHdrSqs.js", | |||
"localHandler":"main", | |||
"functionName":"FunctionNameHdrSqs" // FunctionName is full name of function after deploy | |||
}, | |||
"ProcessComplexFilterHdrSqs":{ | |||
"localLacation":"/src/ProcessComplexFilterHdrSqs.js", | |||
"localHandler":"main", | |||
"functionName":"ProcessComplexFilterHdrSqs" | |||
}, | |||
... | |||
}, | |||
"Dynamodb": { | |||
"filterMain":{ | |||
"tableName":"filterMain" | |||
}, | |||
"tableNameBB":{ | |||
"tableName":"tableNameBB" | |||
}, | |||
... | |||
} | |||
} | |||
</syntaxhighlight> | |||
## '''events.json''' | |||
##* Multiple eventTags can be added to a single file | |||
##* Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// Layout of file events.json | |||
{ | |||
input:{}, | |||
output:{}, | |||
dynamodb:{} | |||
} | |||
// An example of naming an eventTag for each event | |||
{ | |||
"Complexfilter_ProcessComplexfilter_logical_basic": {}, // for input | |||
"Output_Complexfilter_ProcessComplexfilter_logical_basic": {}, // for output | |||
"Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain": {} // for dynamodb | |||
} | |||
</syntaxhighlight> | |||
##* "Complexfilter_ProcessComplexfilter_logical_basic" is called '''{inputEventTag}''' | |||
##* for {outputEventTag} is '''Output_{inputEvenTag}''' | |||
##:: eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic" | |||
##* for dynamodb is '''{inputEventTag}__dynamodb_{action}_{tablename}''' | |||
##:: eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain" | |||
##: <u>'''{action}''' is only ''put'' or ''update'', and in case of ''update'', must only test the last step of update </u> | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// An example input and output event of Sns/Sqs, Dsq and Invoke | |||
{ | |||
"Complexfilter_ProcessComplexfilter_logical_basic": { | |||
"forStageMatching": true, | |||
"properties": { | |||
"propertyA": { | |||
"forStageMatching": true, | |||
"value": "valueProperty1", | |||
}, | |||
"propertyB": { | |||
"testValueMatches": false, // no child properties will be tested | |||
"properties": { | |||
"propertyB1": { | |||
"value": "valuePropertyB1", | |||
} | |||
} | |||
}, | |||
"propertyC": { | |||
"eventValue": [ | |||
"valuePropertyC1", | |||
"valuePropertyC2", | |||
"valuePropertyC3", | |||
] | |||
} | |||
}, | |||
// settings for Sns/Sqs | |||
"snsSqsTrigger": true, // set when event is initial stage of Sns | |||
"messageAttributes": { // optional | |||
"forStageMatching": true, | |||
"properties": { | |||
"msgTag": { // require | |||
"value": "msgTag" | |||
}, | |||
"propertyD": { | |||
"forStageMatching": true, // default: false, whether this property is used to match stage config during integration tests | |||
"testValueMatches": false, // default: true, whether value of this property is checked when performing test | |||
"value": "valuePropertyD" | |||
} | |||
} | |||
} | |||
// settings for Dsq | |||
// DirectSqs set in HdrDsq if have messageAttributeValidatorSchema and required property in messageAttributes eg: messageTag | |||
"DirectSqs": true, // set when event is initial stage of Dsq | |||
"messageAttributes": { // optional | |||
"messageTag": { | |||
"DataType": "String", | |||
"StringValue": "messageAttributes_is" | |||
} | |||
} | |||
}, | |||
"Output_Complexfilter_ProcessComplexfilter_logical_basic": { | |||
"forStageMatching": true, | |||
"properties": { | |||
"propertyA": { | |||
"forStageMatching": true, | |||
"value": "valueProperty1", | |||
} | |||
... | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
##* <code>forStageMatching</code> default: false, whether this property is used to match stage config during integration tests. <u> Use in test importent parameter </u> | |||
##* <code>testValueMatches</code> default: true, whether value of this property is checked when performing test. <u>For random eg. timeStamp or uuid </u> | |||
##* If value in array or number or string is <u>random</u>. '''Use testValueMatches: true not set forStageMatching: true''' | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// An example input and output event of API | |||
{ | |||
"LambdaFunctionHdrApi_input__pass_notTestAuthorizer": { | |||
"forstageMatvhing": true, | |||
"properties": { | |||
"body": { | |||
"properties": { | |||
"propertyA": { | |||
"testValueMatches": false, | |||
"value": "valueProperty1", | |||
}, | |||
"propertyB": { | |||
"properties": { | |||
"propertyB1": { | |||
"value": "valuePropertyB1", | |||
} | |||
} | |||
}, | |||
"propertyC": { | |||
"eventValue": [ | |||
"valuePropertyC1", | |||
"valuePropertyC2", | |||
"valuePropertyC3", | |||
] | |||
}, | |||
... | |||
} | |||
} | |||
} | |||
}, | |||
"Output_LambdaFunctionHdrApi_input__pass_notTestAuthorizer": { | |||
"properties": { | |||
"body": { | |||
"properties": { | |||
"propertyA": { | |||
"testValueMatches": false, | |||
"value": "valueProperty1" | |||
}, | |||
... | |||
} | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// An example event of Dynamodb | |||
{ | |||
{inputEventTag}__dynamodb_{action}_{tablename}: { // eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain" | |||
"forStageMatching": true, | |||
"properties": { | |||
(property is update)... | |||
}, | |||
"keyValues": { | |||
{partitionKey}: "4865d2451a621cb7f71225cfabf2df4f98e20801 ", | |||
{sortKey}: "cdb170690571df7522b3850920fce02507c077ee" | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// An example event of NoRetryError output | |||
{ | |||
Output_{inputEvenTag}: { // eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic" | |||
"forStageMatching": true, | |||
"properties": { | |||
"errorMessage": { | |||
"value": "Not found schema of {serviceTag:TestGraphHandler, objectType:notFoundObjType}" | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
## '''tests.json''' | |||
##:<syntaxhighlight lang="JavaScript"> | |||
// An example test | |||
[ | |||
{ | |||
"integrationTestTag": "test_S3_ByDev", | |||
"productionSafe": false, | |||
"errorIfStageUnderfined": false, | |||
"errorIfInvokeUnderfined": false, | |||
"stages": [ | |||
{ | |||
"initialStage": true, | |||
"inputEventTag": "Complexfiter_ProcessComplexfiter_logical_basic", | |||
"serviceName": "ComplexFilter", | |||
"resourceType": "Lambda", | |||
"resourceName": "ProcessComplexFilterHdrSqs", | |||
"snsServiceName": "ComplexFilter", // if snsSqsTrigger = true but not set snsServiceName or snsTopic --> will direct invoke | |||
"snsTopic": "InProcessComplexFilter", // if snsSqsTrigger = true but not set snsServiceName or snsTopic --> will direct invoke | |||
"outputEventTag": "Output_Complexfiter_ProcessComplexfiter_logical_basic", | |||
// Settings if have test dynamodb | |||
"dynamodbOutputEventIdentifiers": [ | |||
{ | |||
"serviceName": "ComplexFilter", | |||
"resourceName": "FilterMain", | |||
"eventTag": "Complexfiter_ProcessComplexfiter_logical_basic_dynamodb_update_FilterMain" | |||
}, | |||
... | |||
], | |||
// Settings multiple stage for invoke | |||
"invokes": [ | |||
{ | |||
"eventStageTag": "GraphHandler_GetNodeV2_NomalCase" | |||
}, | |||
... | |||
], | |||
}, | |||
{ | |||
"eventStageTag": "GraphHandler_GetNodeV2_NomalCase" // require "eventStageTag" if have settings multiple stage for invoke | |||
"inputEventTag": "SellOfferMgr_ProcessLogical_logical_integrationTesting_returnObject", | |||
"serviceName": "SellOfferMgr", | |||
"resourceType": "Lambda", | |||
"resourceName": "ProcessLogicalHdrSqs", | |||
"outputEventTag": "output_intTesting_ProcessLogical_logical_integrationTesting_returnObject", | |||
}, | |||
... | |||
] | |||
}, | |||
... | |||
] | |||
</syntaxhighlight> |
Revision as of 08:39, 18 February 2025
Overview
Setup integrationtest
Step 1; Create object in bucket
- Create your folder in bucket integrationtest-config-us-east-2/test_config/{your folder name} in S3 bucket
- {your folder name} maybe is your nickname eg. jamesDev, nicoleDev
- Can create a subfolder in your folder for each test case or service that you want to test
- eg. - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager
- - integrationtest-config-us-east-2/test_config/jamesDev/ProcessLogical
- - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/ProcessLogical
- eg. - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager
- Create a file in a folder that is used for testing
- resources.json / events.json / tests.json
- resources.json and events.json is json object
- tests.json is json array of objects
- Can create these files in a SharedResource folder and share it with another test for collaborative usage
- eg. integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/SharedResource/resources.json
- In the main prefix for testing, you don’t need to upload every file. If you have a file in SharedResource, you can skip uploading it
- resources.json
- Have 2 main object keys is Lambda and Dynamodb
{ "Lambda":{ "{FunctionNameHdrSqs}":{ "localLacation":"/src/FunctionNameHdrSqs.js", "localHandler":"main", "functionName":"FunctionNameHdrSqs" // FunctionName is full name of function after deploy }, "ProcessComplexFilterHdrSqs":{ "localLacation":"/src/ProcessComplexFilterHdrSqs.js", "localHandler":"main", "functionName":"ProcessComplexFilterHdrSqs" }, ... }, "Dynamodb": { "filterMain":{ "tableName":"filterMain" }, "tableNameBB":{ "tableName":"tableNameBB" }, ... } }
- events.json
- Multiple eventTags can be added to a single file
- Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError
// Layout of file events.json { input:{}, output:{}, dynamodb:{} } // An example of naming an eventTag for each event { "Complexfilter_ProcessComplexfilter_logical_basic": {}, // for input "Output_Complexfilter_ProcessComplexfilter_logical_basic": {}, // for output "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain": {} // for dynamodb }
- "Complexfilter_ProcessComplexfilter_logical_basic" is called {inputEventTag}
- for {outputEventTag} is Output_{inputEvenTag}
- eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic"
- for dynamodb is {inputEventTag}__dynamodb_{action}_{tablename}
- eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain"
- {action} is only put or update, and in case of update, must only test the last step of update
// An example input and output event of Sns/Sqs, Dsq and Invoke { "Complexfilter_ProcessComplexfilter_logical_basic": { "forStageMatching": true, "properties": { "propertyA": { "forStageMatching": true, "value": "valueProperty1", }, "propertyB": { "testValueMatches": false, // no child properties will be tested "properties": { "propertyB1": { "value": "valuePropertyB1", } } }, "propertyC": { "eventValue": [ "valuePropertyC1", "valuePropertyC2", "valuePropertyC3", ] } }, // settings for Sns/Sqs "snsSqsTrigger": true, // set when event is initial stage of Sns "messageAttributes": { // optional "forStageMatching": true, "properties": { "msgTag": { // require "value": "msgTag" }, "propertyD": { "forStageMatching": true, // default: false, whether this property is used to match stage config during integration tests "testValueMatches": false, // default: true, whether value of this property is checked when performing test "value": "valuePropertyD" } } } // settings for Dsq // DirectSqs set in HdrDsq if have messageAttributeValidatorSchema and required property in messageAttributes eg: messageTag "DirectSqs": true, // set when event is initial stage of Dsq "messageAttributes": { // optional "messageTag": { "DataType": "String", "StringValue": "messageAttributes_is" } } }, "Output_Complexfilter_ProcessComplexfilter_logical_basic": { "forStageMatching": true, "properties": { "propertyA": { "forStageMatching": true, "value": "valueProperty1", } ... } } }
forStageMatching
default: false, whether this property is used to match stage config during integration tests. Use in test importent parametertestValueMatches
default: true, whether value of this property is checked when performing test. For random eg. timeStamp or uuid- If value in array or number or string is random. Use testValueMatches: true not set forStageMatching: true
// An example input and output event of API { "LambdaFunctionHdrApi_input__pass_notTestAuthorizer": { "forstageMatvhing": true, "properties": { "body": { "properties": { "propertyA": { "testValueMatches": false, "value": "valueProperty1", }, "propertyB": { "properties": { "propertyB1": { "value": "valuePropertyB1", } } }, "propertyC": { "eventValue": [ "valuePropertyC1", "valuePropertyC2", "valuePropertyC3", ] }, ... } } } }, "Output_LambdaFunctionHdrApi_input__pass_notTestAuthorizer": { "properties": { "body": { "properties": { "propertyA": { "testValueMatches": false, "value": "valueProperty1" }, ... } } } } }
// An example event of Dynamodb { {inputEventTag}__dynamodb_{action}_{tablename}: { // eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain" "forStageMatching": true, "properties": { (property is update)... }, "keyValues": { {partitionKey}: "4865d2451a621cb7f71225cfabf2df4f98e20801 ", {sortKey}: "cdb170690571df7522b3850920fce02507c077ee" } } }
// An example event of NoRetryError output { Output_{inputEvenTag}: { // eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic" "forStageMatching": true, "properties": { "errorMessage": { "value": "Not found schema of {serviceTag:TestGraphHandler, objectType:notFoundObjType}" } } } }
- tests.json
// An example test [ { "integrationTestTag": "test_S3_ByDev", "productionSafe": false, "errorIfStageUnderfined": false, "errorIfInvokeUnderfined": false, "stages": [ { "initialStage": true, "inputEventTag": "Complexfiter_ProcessComplexfiter_logical_basic", "serviceName": "ComplexFilter", "resourceType": "Lambda", "resourceName": "ProcessComplexFilterHdrSqs", "snsServiceName": "ComplexFilter", // if snsSqsTrigger = true but not set snsServiceName or snsTopic --> will direct invoke "snsTopic": "InProcessComplexFilter", // if snsSqsTrigger = true but not set snsServiceName or snsTopic --> will direct invoke "outputEventTag": "Output_Complexfiter_ProcessComplexfiter_logical_basic", // Settings if have test dynamodb "dynamodbOutputEventIdentifiers": [ { "serviceName": "ComplexFilter", "resourceName": "FilterMain", "eventTag": "Complexfiter_ProcessComplexfiter_logical_basic_dynamodb_update_FilterMain" }, ... ], // Settings multiple stage for invoke "invokes": [ { "eventStageTag": "GraphHandler_GetNodeV2_NomalCase" }, ... ], }, { "eventStageTag": "GraphHandler_GetNodeV2_NomalCase" // require "eventStageTag" if have settings multiple stage for invoke "inputEventTag": "SellOfferMgr_ProcessLogical_logical_integrationTesting_returnObject", "serviceName": "SellOfferMgr", "resourceType": "Lambda", "resourceName": "ProcessLogicalHdrSqs", "outputEventTag": "output_intTesting_ProcessLogical_logical_integrationTesting_returnObject", }, ... ] }, ... ]