Developer guide for making Integration Tests: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
= Overview =
= Overview =
:How to create folder and file in S3 bucket for prepare integrationTest
:[[Service - Integration Test Config|Integration Test Config]] for config of property in file resources.json, events.json and tests.json
= Setup integrationtest =
= Setup integrationtest =
=== Step 1; Create object in bucket ===
== Create folder ==
# Create your folder in bucket '''integrationtest-config-us-east-2/test_config/{<u>your folder name</u>}''' in S3 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
:* '''{<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
:* 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
:: 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/ProcessLogical
#::: - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/ProcessLogical
::: - integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/ProcessLogical
== Create file ==
# Create a file in a folder that is used for testing
# Create a file in a folder that is used for testing
#* ''resources.json / events.json / tests.json''
#* ''resources.json / events.json / tests.json''
Line 16: Line 19:
#* 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 
#* 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'''
## '''resources.json'''
##* Have 2 main object keys is ''Lambda'' and ''Dynamodb''
##* Syntax; [[Service_-_Integration_Test_Config#resources.js Syntax|resources Syntax]]
##:<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'''
## '''events.json'''
##* Syntax; [[Service_-_Integration_Test_Config#events/*.js_Syntax|events Syntax]]
##* Not use <code><s>isObject</s></code>. Use <code>properties</code> instead, if is an object will look for child properties
##* Not use <code><s>isStringSet</s></code>
##* If have many stage, Set <code>initialStage</code> is true only initial stage. Next stage not set this setting
##* If <code>snsSqsTrigger</code> is true but not set snsServiceName or snsTopic --> direct invoke
##* If <code>DirectSqs</code> and <code>BatchSqsMessages</code> is true --> direct invoke
##* If <code>snsSqsTrigger</code> and <code>DirectSqs</code> is false or not set --> direct invoke
##* <code>forStageMatching</code> <u>Use in test important parameter</u>
##* <code>testValueMatches</code> <u>For random parameter eg. timeStamp or uuid</u>
##* If value in array or number or string is <u>random</u>. '''Use testValueMatches: true not set forStageMatching: true''' 
##* Multiple eventTags can be added to a single file
##* Multiple eventTags can be added to a single file
##* Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError  
##* Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError  
##:<syntaxhighlight lang="JavaScript">
## '''tests.json'''
// Layout of file events.json  
##* Syntax; [[Service_-_Integration_Test_Config#tests/*.js_Syntax|tests Syntax]]
{  
##* Not use <code><s>dynamoDbOutput</s></code>. Use <code>dynamodbOutputEventIdentifiers</code> instead
input:{},  
# Upload file to S3 bucket by batchscript or upload to S3 bucket directly
output:{},  
#:<syntaxhighlight lang="JavaScript">
dynamodb:{}
#!/bin/bash
set -u
 
localPath="/home/dogsrcute/Programming mint/Fixed_Integrationtest/PluemDev/paginate/2stages"
bucketName=s3://integrationtest-config-us-east-2/test_config/mintDev/fixed/PluemDev/2stages/  
 
aws s3 cp "$localPath" "$bucketName" --recursive
</syntaxhighlight>
#* localPath is part to files for upload
#* bucketName is your bucket
== Type of parameter ==
: Parameter type for create property in events.json
<syntaxhighlight lang="JavaScript">
object: {  
forStageMatching: true,
properties: {}  
},
array: {
forStageMatching: true,  
eventValue: []
},
number: {  
forStageMatching: true,
value: 1111
},
string: {
forStageMatching: true,  
value: "hi"
},
boolean: {  
forStageMatching: true,
value: true
}  
}  


// An example of naming an eventTag for each event
// Case empty
{
EmptyString:{  
"Complexfilter_ProcessComplexfilter_logical_basic": {},           // for input
value: ""  
"Output_Complexfilter_ProcessComplexfilter_logical_basic": {},       // for output
},
"Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain": {} // for dynamodb
EmptyArray:{  
forStageMatching: true,
eventValue: []
},  
EmptyObject:{
forStageMatching: true,  
value: {}  
}
}
</syntaxhighlight>
</syntaxhighlight>
##* "Complexfilter_ProcessComplexfilter_logical_basic" is called '''{inputEventTag}'''
= Test =
##* for {outputEventTag} is '''Output_{inputEvenTag}'''
# create params for invoke <u>IntTestingTestInitiateIntegrationTestHdrInv</u> function
##:: eg. "Output_Complexfilter_ProcessComplexfilter_logical_basic"
#:<syntaxhighlight lang="JavaScript">
##* for dynamodb is '''{inputEventTag}__dynamodb_{action}_{tablename}'''
{  
##:: eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain"
"serviceName": "ComplexFilter",
##: <u>'''{action}''' is only ''put'' or ''update'', and in case of ''update'', must only test the last step of update </u>
"resourceType": "Lambda",   
##:<syntaxhighlight lang="JavaScript">
"resourceName": "ProcessComplexFilterHdrSqs",   
// An example input and output event of Sns/Sqs, Dsq and Invoke
"integrationTestTags": [  
{
"test_S3_ByDev"   
"Complexfilter_ProcessComplexfilter_logical_basic": {
],
"forStageMatching": true,      
"bucketName": "integrationtest-config-us-east-2",   
"properties": {
"bucketPrefix":[   
"propertyA": {
"test_config/mintDev/basicCase/",  
"forStageMatching": true,   
"test_config/mintDev/SharedResource/"   
"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>
</syntaxhighlight>
# Find results in IntTestingTestTestRecord table

Revision as of 07:12, 21 February 2025

Overview

How to create folder and file in S3 bucket for prepare integrationTest
Integration Test Config for config of property in file resources.json, events.json and tests.json

Setup integrationtest

Create folder

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

Create file

  1. 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 
    1. resources.json
    2. events.json
      • Syntax; events Syntax
      • Not use isObject. Use properties instead, if is an object will look for child properties
      • Not use isStringSet
      • If have many stage, Set initialStage is true only initial stage. Next stage not set this setting
      • If snsSqsTrigger is true but not set snsServiceName or snsTopic --> direct invoke
      • If DirectSqs and BatchSqsMessages is true --> direct invoke
      • If snsSqsTrigger and DirectSqs is false or not set --> direct invoke
      • forStageMatching Use in test important parameter
      • testValueMatches For random parameter eg. timeStamp or uuid
      • If value in array or number or string is random. Use testValueMatches: true not set forStageMatching: true
      • Multiple eventTags can be added to a single file
      • Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError
    3. tests.json
      • Syntax; tests Syntax
      • Not use dynamoDbOutput. Use dynamodbOutputEventIdentifiers instead
  2. Upload file to S3 bucket by batchscript or upload to S3 bucket directly
    #!/bin/bash 
    set -u 
    
    localPath="/home/dogsrcute/Programming mint/Fixed_Integrationtest/PluemDev/paginate/2stages" 
    bucketName=s3://integrationtest-config-us-east-2/test_config/mintDev/fixed/PluemDev/2stages/ 
    
    aws s3 cp "$localPath" "$bucketName" --recursive
    
    • localPath is part to files for upload
    • bucketName is your bucket

Type of parameter

Parameter type for create property in events.json
object: { 
	forStageMatching: true, 
	properties: {} 
}, 
array: { 
	forStageMatching: true, 
	eventValue: [] 
}, 
number: { 
	forStageMatching: true, 
	value: 1111 
}, 
string: { 
	forStageMatching: true, 
	value: "hi" 
}, 
boolean: { 
	forStageMatching: true, 
	value: true 
} 

// Case empty 
EmptyString:{ 
	value: "" 
}, 
EmptyArray:{ 
	forStageMatching: true, 
	eventValue: [] 
}, 
EmptyObject:{ 
	forStageMatching: true, 
	value: {} 
}

Test

  1. create params for invoke IntTestingTestInitiateIntegrationTestHdrInv function
    { 
    	"serviceName": "ComplexFilter",  
    	"resourceType": "Lambda",  
    	"resourceName": "ProcessComplexFilterHdrSqs",  
    	"integrationTestTags": [ 
    		"test_S3_ByDev"  
    	],  
    	"bucketName": "integrationtest-config-us-east-2",  
    	"bucketPrefix":[  
    		"test_config/mintDev/basicCase/", 
    		"test_config/mintDev/SharedResource/"  
    	]  
    }
    
  2. Find results in IntTestingTestTestRecord table