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 Dsq
  • 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}" 
			} 
		} 
	} 
}

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 Dsq
  • 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

initalStage

Sns

[
   {
      "integrationTestTag":"test_S3_ByDev",
      "productionSafe":false,
      "errorIfStageUnderfined":false,
      "errorIfInvokeUnderfined":false,
      "stages":[
         {
            "initialStage":true,
            "inputEventTag":"Complexfiter_ProcessComplexfiter_logical_basic",
            "serviceName":"IntCPF",
            "resourceType":"Lambda",
            "resourceName":"ProcessComplexFilterHdrSqs",
            "snsServiceName":"IntCPF",
            "snsTopic":"InProcessComplexFilter",
            "outputEventTag":"Output_Complexfiter_ProcessComplexfiter_logical_basic"
         }
      ]
   }
]
  • If stage test is sns but is not initial stage not set property snsServiceName and sns Topic.

Dsq

[
   {
      "integrationTestTag":"test_S3_ByDev_Dsq",
      "productionSafe":false,
      "errorIfStageUnderfined":false,
      "errorIfInvokeUnderfined":false,
      "stages":[
         {
            "initialStage":true,
            "inputEventTag":"Locations_ProcessLocationNodeSomting_casenotHaveData",
            "serviceName":"Locations",
            "resourceType":"Lambda",
            "resourceName":"ProcessLocationNodeSomtingHdrDsq",
            "outputEventTag":"Output_Locations_ProcessLocationNodeSomting_casenotHaveData"
         }
      ]
   }
]

Invoke

single stage

{
   "integrationTestTag":"LambdaFunctionHdrInv__pass",
   "productionSafe":false,
   "errorIfStageUndefined":false,
   "errorIfInvokeUndefined":false,
   "stages":[
      {
         "initialStage":true,
         "inputEventTag":"LambdaFunctionHdrInv_input__pass",
         "serviceName":"ServiceTemplate",
         "resourceType":"Lambda",
         "resourceName":"LambdaFunctionHdrInv",
         "outputEventTag":"LambdaFunctionHdrInv_output__pass"
      }
   ]
}

invoke multiple stage

  • Each stage test can invoke multiple lambda by use "eventStage Tag" point to stage for test integration test.

{

  "integrationTestTag":"LambdaFunctionHdrInv_invokes__pass",
  "productionSafe":false,
  "errorIfStageUndefined":false,
  "errorIfInvokeUndefined":false,
  "stages":[
     {
        "initialStage":true,
        "inputEventTag":"LambdaFunctionHdrInv_input__pass",
        "serviceName":"ServiceTemplate",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunctionHdrInv",
        "outputEventTag":"LambdaFunctionHdrInv_output__pass",
        "invokes":[
           {
              "eventStageTag":"service_invokes__pass"
           },
           {
              "eventStageTag":"service_invokesD__pass"
           }
        ]
     },
     {
        "eventStageTag":"service_invokesB__pass",
        "inputEventTag":"input_service_invokes__pass",
        "serviceName":"ServiceTemplate_B",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunction_B_HdrInv",
        "outputEventTag":"output_service_invokes__pass"
     },
     {
        "eventStageTag":"service_invokesD__pass",
        "inputEventTag":"input_service_invokesD__pass",
        "serviceName":"ServiceTemplate_D",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunction_D_HdrInv",
        "outputEventTag":"output_service_invokesD__pass"
     }
  ]

}

Api

[
   {
      "integrationTestTag":"LambdaFunctionHdrApi__pass",
      "productionSafe":false,
      "errorIfStageUndefined":false,
      "errorIfInvokeUndefined":false,
      "stages":[
         {
            "initialStage":true,
            "inputEventTag":"LambdaFunctionHdrApi_input__pass",
            "serviceName":"ServiceTemplate",
            "resourceType":"Lambda",
            "resourceName":"LambdaFunctionHdrApi",
            "outputEventTag":"LambdaFunctionHdrApi_output__pass"
         }
      ]
   }
]

case invoke multiple stage

  • Each stage test can invoke multiple lambda by use "eventStage Tag" point to stage for test integration test.

{

  "integrationTestTag":"LambdaFunctionHdrInv_invokes__pass",
  "productionSafe":false,
  "errorIfStageUndefined":false,
  "errorIfInvokeUndefined":false,
  "stages":[
     {
        "initialStage":true,
        "inputEventTag":"LambdaFunctionHdrInv_input__pass",
        "serviceName":"ServiceTemplate",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunctionHdrInv",
        "outputEventTag":"LambdaFunctionHdrInv_output__pass",
        "invokes":[
           {
              "eventStageTag":"service_invokes__pass"
           },
           {
              "eventStageTag":"service_invokesD__pass"
           }
        ]
     },
     {
        "eventStageTag":"service_invokesB__pass",
        "inputEventTag":"input_service_invokes__pass",
        "serviceName":"ServiceTemplate_B",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunction_B_HdrInv",
        "outputEventTag":"output_service_invokes__pass"
     },
     {
        "eventStageTag":"service_invokesD__pass",
        "inputEventTag":"input_service_invokesD__pass",
        "serviceName":"ServiceTemplate_D",
        "resourceType":"Lambda",
        "resourceName":"LambdaFunction_D_HdrInv",
        "outputEventTag":"output_service_invokesD__pass"
     }
  ]

}

Api

[
   {
      "integrationTestTag":"LambdaFunctionHdrApi__pass",
      "productionSafe":false,
      "errorIfStageUndefined":false,
      "errorIfInvokeUndefined":false,
      "stages":[
         {
            "initialStage":true,
            "inputEventTag":"LambdaFunctionHdrApi_input__pass",
            "serviceName":"ServiceTemplate",
            "resourceType":"Lambda",
            "resourceName":"LambdaFunctionHdrApi",
            "outputEventTag":"LambdaFunctionHdrApi_output__pass"
         }
      ]
   }
]