2025-02-20 - Integration Test examples

From Izara Wiki
Jump to navigation Jump to search

Service - Integration Testing

Service - Integration Test Config

Overview

The example of propeerties in resources.json, events.json and tests.json for upload to S3 bucket
Integration Test Config for config of each property in these files

resources.json

{ 
	"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

// Layout of file events.json 
{ 
	input:{}, 
	output:{}, 
	dynamodb:{} // optional
} 

// 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
}
  • eventTag :inputEventTag,outputEventTag,dynamodbTag
create name eventTag not duplicate.
  • "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
    • can add manu event in one file but eventTag(input,output,dynamo) not duplicate

sns

// An example input and output event of Sns
{
   "LambdaFunctionHdrSqs_input__pass":{
      "forStageMatching":true,
      "properties":{
         "propertyA":{
            "forStageMatching":true,
            "value":"valueProperty1"
         },
         "propertyB":{
            "forStageMatching":true,
            "properties":{
               "propertyB1":{
                  "forStageMatching":true,
                  "value":"valuePropertyB1"
               }
            }
         },
         "propertyC":{
            "eventValue":[
               "valuePropertyC1",
               "valuePropertyC2",
               "valuePropertyC3"
            ]
         }
      },
      "snsSqsTrigger":true,
      "messageAttributes":{
         "forStageMatching":true,
         "properties":{
            "msgTag":{
               "forStageMatching":true,
               "value":"msgTag"
            },
            "propertyD":{
               "forStageMatching":true,
               "value":"valuePropertyD"
            }
         }
      }
   },
   {
      "output_LambdaFunctionHdrSqs_pass":{
         "forStageMatching":true,
         "properties":{
            "propertyA":{
               "forStageMatching":true,
               "value":"valueProperty1"
            }
         }
      }
   }
}
  • snsSqsTrigger = true
for initialStage of sns
  • messageAttributes is optional

Dsq

// An example input and output event of Direct Sqs
{
   "LambdaFunctionHdrDsq_input__pass":{
      "forStageMatching":true,
      "properties":{
         "propertyA":{
            "forStageMatching":true,
            "value":"valueProperty1"
         },
         "propertyB":{
            "forStageMatching":true,
            "properties":{
               "propertyB1":{
                  "forStageMatching":true,
                  "value":"valuePropertyB1"
               }
            }
         },
         "propertyC":{
            "eventValue":[
               "valuePropertyC1",
               "valuePropertyC2",
               "valuePropertyC3"
            ]
         }
      },
      "DirectSqs":true,
      "messageAttributes":{
         "forStageMatching":true,
         "properties":{
            "msgTag":{
               "forStageMatching":true,
               "value":"msgTag"
            },
            "propertyD":{
               "forStageMatching":true,
               "value":"valuePropertyD"
            }
         }
      }
   },
   {
      "output_LambdaFunctionHdrDsq_pass":{
         "forStageMatching":true,
         "properties":{
            "propertyA":{
               "forStageMatching":true,
               "value":"valueProperty1"
            }
         }
      }
   }
}
  • DirectSqs = true
for initialStage of sns
  • messageAttributes is optional

Invoke

{
  "LambdaFunctionHdrInv_input__pass":{
     "forStageMatching":true,
     "properties":{
        "propertyA":{
           "forStageMatching":true,
           "value":"valueProperty1"
        },
        "propertyB":{
           "forStageMatching":true,
           "properties":{
              "propertyB1":{
                 "forStageMatching":true,
                 "value":"valuePropertyB1"
              }
           }
        }
     }
    },
    {
        "output_LambdaFunctionHdrInv_pass":{
           "forStageMatching":true,
           "properties":{
              "propertyA":{
                 "forStageMatching":true,
                 "value":"valueProperty1"
              }
           }
        }
     }
}

API

// 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"
					}, 
					...
				} 
			} 
		}  
	}
}

Dynamodb

// An example event of Dynamodb //optional 
{
	{inputEventTag}__dynamodb_{action}_{tablename}: { // eg. "Complexfilter_ProcessComplexfilter_logical_basic__dynamodb_update_FilterMain"
	"forStageMatching": true,
     "properties": {
        "filterMainUniqueRequestId": {
          "testValueMatches": true,
          "value": "bbc4f4a9-2032-4dec-9129-8c7d169fecc5"
         },
        "filterObject": {
        "forStageMatching": true,
        "properties": {
          "logicalType": {
            "value": "partitionKey"
          },
          "comparison": {
            "value": "equals"
          },
          "type": {
            "value": "logical"
          },
          "partitionKey": {
            "forStageMatching": true,
            "value": "mockIntegratioTestCPF"
          }
        }
      },
      "filterMainExpiryTime": {
        "testValueMatches": true,
        "value": 1731980802858
      },
      "filterMainStatus": {
       "forStageMatching": true,
        "value": "processing"
      },
      "createTime": {
        "testValueMatches": true,
        "value": 1731894402678
      },
      "objType": {
        "forStageMatching": true,
        "properties": {
          "serviceTag": {
            "forStageMatching": true,
            "value": "IntTesting"
          },
          "objectType": {
            "forStageMatching": true,
            "value": "TestRecord"
          }
        }
      }
    },
    "keyValues": {
      "filterMainId": "4865d2451a621cb7f71225cfabf2df4f98e20801",
      "objTypeId": "cdb170690571df7522b3850920fce02507c077ee"
    }
	} 
}
  • partition key: filterMainId
  • sort key: objTypeId

NoRetryError

// 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,
		"errorIfStageUndefined": false, 
		"errorIfInvokeUndefined": 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 --> direct invoke 
				"snsTopic": "InProcessComplexFilter",  // if snsSqsTrigger = true but not set snsServiceName or snsTopic --> direct invoke
				"outputEventTag": "Output_Complexfiter_ProcessComplexfiter_logical_basic", 
				"BatchSqsMessages": true
				
				// 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", 
			},
			... 
		] 
	},
	... 
]