Developer guide for making Integration Tests: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
 
(29 intermediate revisions by the same user not shown)
Line 2: Line 2:
:How to create folder and file in S3 bucket for prepare integrationTest
: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
:[[Service - Integration Test Config|Integration Test Config]] for config of property in file resources.json, events.json and tests.json
= Setup integrationtest =
=Buckets3=
integrationtest-config-us-east-2
:'''Folder'''
:-seedData_integrationTest
:-test_config
 
=SeedData=
integrationtest manager seed date 2 process
 
*1.SeedDataTag
*2.SeedData_integrationTest
 
==SeedDataTag==
:Data for work test eg: test complexfilter may much have seed datafrom external service for save data in table filterData,So can be mock data external servcie use 'SeedDataTag' prepare data of test.
:'''1. save file in servcie IntegrationTestConfig folder test_config '''
:'''2. save in s3 in folder test_config/{dev name}'''
::eg:[https://us-east-2.console.aws.amazon.com/s3/buckets/integrationtest-config-us-east-2?region=us-east-2&prefix=test_config/mintDev/testRefreshSeedData/&showversions=false|example save file seed data tag]
 
folder
*dynamoDBSeedDataTags.json
*graphSeedDataTags.json
SynTax seedDataTag:
:[[2025-11-20 IntegrationTest#tests#RefreshSeedData#dynamoDBSeedDataTags|'''dynamoDBSeedDataTags''']]
:[[2025-11-20 IntegrationTest#tests#RefreshSeedData#graphSeedDataTags|'''graphSeedDataTags''']]
 
==seedData_integrationTest==
''seeddata s3'' for other dev use service,If a developer wants to add more for other important testing purposes,
they can add it from the s3 bucket at this point and run [[Developer guide for making Integration Tests#refreshSeedData|batch RefreshSeedData]]
to clean up the seed data in the table after it creates seed data form service deploy and pulls ''seeddata s3'.
*How to create folder and sort folder.
 
===regenerateSeedDynamodb===
seed data for dynamodb
<syntaxhighlight lang="JavaScript" inline>integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase}
/mainServcie/regenerateSeedDynamodb/(otherSercie for use db)/{tableName.json}</syntaxhighlight>
 
===regenerateSeedGraph===
seed data for graph
:- nodeConfig
<syntaxhighlight lang="JavaScript" inline>
integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase}
/mainServcie/regenerateSeedGraph/(other servcie for use graph)/(service graphandler)/(nodeConfig)/{other servie.json}                                                                             
</syntaxhighlight>
 
:- relationshipConfig
<syntaxhighlight lang="JavaScript" inline>
integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase}
/mainServcie/regenerateSeedGraph/(other servcie for use graph)/(service graphandler)/(relationship)/{other servie.json}                                                                             
</syntaxhighlight>
 
=Test config=
== Create folder ==
== Create folder ==
*create folder in buckets s3
*create folder in buckets s3
::'''integrationtest-config-us-east-2/test_config/{<u>your folder name</u>}'''
*https://us-east-2.console.aws.amazon.com/s3/buckets/integrationtest-config-us-east-2?region=us-east-2&bucketType=general
:'''integrationtest-config-us-east-2/test_config/{<u>your folder name</u>}'''
*<u>'''your folder name'''</u>
*<u>'''your folder name'''</u>
::1.Create name Developer for folder name inside test_config  
::1.Create '''name Developer''' for folder name inside test_config  
::2.Create folder '''service Names''' of Test  
::2.Create folder '''service Names''' of Test  
::3.Create '''folder your test'''  
::3.Create '''folder your test'''
::: integrationtest-config-us-east-2/test_config/{'''nameDeveloper'''}/{'''serviceNames'''}/{'''foldeTest'''}/
:: eg. integrationtest-config-us-east-2/test_config/'''mintDev'''/'''complexFilter'''/'''basicCase'''/
:: eg. integrationtest-config-us-east-2/test_config/'''mintDev'''/'''complexFilter'''/'''basicCase'''/
::4.Can save file events, tests,resources inside  
::4.Can save file events, tests,resources inside  
Line 16: Line 68:


== Create file ==
== Create file ==
# Create a file in a folder that is used for testing
*'''files upload in s3''''
#* ''resources.json / events.json / tests.json''
:-resources.json
#* '''resources.json''' and '''events.json''' is json object
:-events.json
#* '''tests.json''' is json array of objects
:-tests.json
#* Can create these files in a SharedResource folder and share it with another test for collaborative usage
::1.'''resources.json''' and '''events.json''' is json object
#:: eg. integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/SharedResource/resources.json
:::note :Can create these files in a SharedResource folder and share it with another test for collaborative usage
#* 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 
:::eg. integrationtest-config-us-east-2/test_config/jamesDev/SellOfferManager/SharedResource/resources.json
## '''resources.json'''
::2.'''tests.json''' is json array of objects
##* Syntax; [[Service_-_Integration_Test_Config#resources.js Syntax|resources Syntax]]
*'''Detail of files'''
## '''events.json'''
::1.'''resources.json'''
##* Syntax; [[Service_-_Integration_Test_Config#events/*.js_Syntax|events Syntax]]
:::*Syntax; [[Service_-_Integration_Test_Config#resources.js Syntax|resources Syntax]]
##* If have many stage, Set <code>initialStage</code> is true only initial stage. Next stage not set this setting
::2.'''events.json'''
##* If <code>snsSqsTrigger</code> is true but not set snsServiceName or snsTopic --> direct invoke  
:::* Syntax; [[Service_-_Integration_Test_Config#events/*.js_Syntax|events Syntax]]
##* If <code>DirectSqs</code> and <code>BatchSqsMessages</code> is true --> direct invoke
:::* If initeage stage <code>snsSqsTrigger</code> is '''true''' but not set snsServiceName or snsTopic
##* If <code>snsSqsTrigger</code> and <code>DirectSqs</code> is false or not set --> direct invoke
:::::-'''sns'''
##* <code>forStageMatching</code> <u>Use in test important parameter</u>
::::::* set <code>snsSqsTrigger</code> is true, if not set or fase ---> direct invoke
##* <code>testValueMatches</code> <u>For random parameter eg. timeStamp or uuid</u>
:::::-'''DirectSqs'''
##* If value in array or number or string is <u>random</u>. '''Use testValueMatches: true not set forStageMatching: true'''
::::::* set <code>BatchSqsMessages</code> is true, if not set or fase ---> direct invoke
##* Multiple eventTags can be added to a single file
:::* <code>forStageMatching</code> <u>Use in '''test important parameter'''</u>
##* Have 6 types of events; Dynamodb, Sns/Sqs, Dsq, Invoke, API and NoRetryError
:::* <code>testValueMatches</code> is default '''true'''
## '''tests.json'''
::: testValueMatches use in case not test parameter random data eg. timeStamp or uuid , but function require paramiter. 
##* Syntax; [[Service_-_Integration_Test_Config#tests/*.js_Syntax|tests Syntax]]
::3.'''tests.json'''
##* Use <code>dynamodbOutputEventIdentifiers</code> instead
:::* Syntax; [[Service_-_Integration_Test_Config#tests/*.js_Syntax|tests Syntax]]
# Upload file to S3 bucket by batchscript or upload to S3 bucket directly
:::*Case test dynamodb (optional test) use <code>dynamodbOutputEventIdentifiers</code> in stage of test
#:<syntaxhighlight lang="JavaScript">
::
#!/bin/bash
*'''Upload file to s3'''
set -u
:1.batchscript
 
::*See [[Developer guide for making Integration Tests#Bash script|upload file to s3]]
localPath="/home/dogsrcute/Programming mint/Fixed_Integrationtest/PluemDev/paginate/2stages"
:2.upload to S3 bucket directly
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 ==
== Type of parameter ==
Line 89: Line 135:
}
}
</syntaxhighlight>
</syntaxhighlight>
= Test =
= Test =
# create params for invoke <u>IntTestingTestInitiateIntegrationTestHdrInv</u> function
:*results of test show in dynamodb table '''IntTestingTestTestRecord'''.
#:<syntaxhighlight lang="JavaScript">
:*How to test integrationtest
:: '''direct invoke''' or '''BashScript'''
1. direct invoke in console lambda function <u>IntTestingTestInitiateIntegrationTestHdrInv</u>
:create params for invoke
:<syntaxhighlight lang="JavaScript">
{  
{  
"serviceName": "ComplexFilter",   
"serviceName": "ComplexFilter",   
Line 106: Line 157:
}  
}  
</syntaxhighlight>
</syntaxhighlight>
# Find results in IntTestingTestTestRecord table
2.BashScript '''integrationTest.sh'''
* see [[Service_-_Integration_Test_Config#Bash script|test integrationtest]]
 
= Setup seedData =
some case much have data before test.In case not own service can be put seedData in bucket s3 and run bashscript "refreshSeedData.sh" for delete old seedData and generate seedData in ownservcie and add on seedData(for use case test) in s3.
* '''1. dynamodb'''
* '''2. graphHandler'''
* '''3. bashscript'''
 
:'''1.dynamodb'''
::1.1 setting in service
:::1.1.1 '''app/__test__/initial_setup/src/ServiceConfig.js'''
:::: in function '''tableConfigs'''
<syntaxhighlight lang="JavaScript">
module.exports.tableConfigs = {
  Config: {
    clearDataWhenRefresh: true
  }
}
</syntaxhighlight>
* '''clearDataWhenRefresh''' set '''true''' if want to refresh seed data.
:::1.1.2 '''/app/sls_yaml/core-function.yml'''
:: Function name '''RemoveSeedDataDynamo'''
:: add role of table want to RemoveSeedData.
 
:'''3.bashscript'''
::* Syntax; [[Developer guide for making Integration Tests#Bash script|refreshSeedData]]
 
= Bash script =
==upload file to s3==
:1.create file '''uploadFileToS3.sh'''
<syntaxhighlight lang="JavaScript">
#!/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
* run interminal in folder '''uploadFileToS3.sh'''
 
2.run Bash Script
<syntaxhighlight lang="JavaScript">
bash uploadFileToS3.sh
</syntaxhighlight>
 
==test integrationtest==
:1 create file '''integrationTest.sh'''
<syntaxhighlight lang="JavaScript">
#!/bin/bash
​set -u
stage="Test"
region="us-east-2"
aws configure set region ${region}
 
declare -a groupTests=(
 
'{
  "serviceName": "DelivMethodSTD",
  "resourceType": "Lambda",
  "resourceName": "MockDeliveryMethod2GetHdrInv",
  "integrationTestTags": [
    "integrationTest_DelivMethodSTD_Get_NomalCase"
  ],
  "bucketName": "integrationtest-config-us-east-2",
  "bucketPrefix": [
    "test_config/mintDev/DelivMethodSTD/getPassed/",
    "test_config/PluemDev/SharedResource/"
  ]
}'
 
)
 
functionName="IntTesting"
 
for test in "${groupTests[@]}"; do
echo "start one set of tests"
echo ${test}
#... invoke InitateTests....
aws lambda invoke \
--function-name "${functionName}${stage}InitiateIntegrationTestHdrInv" \
--payload "${test}" \
--invocation-type RequestResponse \
--cli-binary-format raw-in-base64-out \
/dev/stdout
 
echo "----------- Finish("${functionName}${stage}InitiateIntegrationTestHdrInv") ------------"
done
</syntaxhighlight>
 
:2 run bashscript
<syntaxhighlight lang="JavaScript">
bash integrationTest.sh
</syntaxhighlight>
 
==refreshSeedData==
: 1.create file bashScript "refreshSeedData.sh"
<syntaxhighlight lang="JavaScript">
#!/bin/bash
set -u
declare -a refreshSeedServices=(
"testingMint"
# "DelivMethodSTD"
# ...
)
stage="Test"
region="us-east-2"
 
payload='{
"bucketS3":{
"bucketName":"integrationtest-config-us-east-2",
"bucketPrefix":["seedData_integrationTest/MintDev/caseTestGenerateSeedData/IntTesting/dynamoDB/",
"seedData_integrationTest/MintDev/caseTestGenerateSeedDataA/IntTesting/dynamoDB/"
]
}
}'
payload="${payload:-{}}"
# Check if the payload is still empty and warn the user
if [ "$payload" == "{}" ]; then
    echo "GenerateSeedData form ownservice"
fi
# -------------------------------------------------------------------------------------------------------
for refreshSeedService in "${refreshSeedServices[@]}"; do
echo "start refresh seed graph data for ${refreshSeedService}, function name: ${refreshSeedService}${stage}RemoveSeedDataDynamo"
 
# refresh seed data dynamodb
aws lambda invoke \
--function-name "${refreshSeedService}${stage}RemoveSeedDataDynamo" out\
--cli-binary-format raw-in-base64-out \
--region=${region} || continue
done
echo "Finish run all RemoveSeedDataDynamo"
 
for refreshSeedService in "${refreshSeedServices[@]}"; do
    echo "start refresh seed dynamoDB data for ${refreshSeedService}, function name: ${refreshSeedService}${stage}GenerateSeedDataDynamoTestEnv"
    echo "payload:${payload}"
 
    aws lambda invoke \
    --function-name "${refreshSeedService}${stage}GenerateSeedDataDynamoTestEnv" out \
    --payload "${payload}" \
    --cli-binary-format raw-in-base64-out \
    --region=${region} || continue
done
echo "Finish run all GenerateSeedDataDynamoTestEnv"
 
</syntaxhighlight>
: 2.'''run bashscript'''
<syntaxhighlight lang="JavaScript">
bash refreshSeedData.sh
</syntaxhighlight>


= Working documents =
= Working documents =


[[:Category:Working_documents - Developer guide for making Integration Tests|Working_documents - Developer guide for making Integration Tests]]
[[:Category:Working_documents - Developer guide for making Integration Tests|Working_documents - Developer guide for making Integration Tests]]

Latest revision as of 07:23, 24 November 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

Buckets3

integrationtest-config-us-east-2

Folder
-seedData_integrationTest
-test_config

SeedData

integrationtest manager seed date 2 process

  • 1.SeedDataTag
  • 2.SeedData_integrationTest

SeedDataTag

Data for work test eg: test complexfilter may much have seed datafrom external service for save data in table filterData,So can be mock data external servcie use 'SeedDataTag' prepare data of test.
1. save file in servcie IntegrationTestConfig folder test_config
2. save in s3 in folder test_config/{dev name}
eg:save file seed data tag

folder

  • dynamoDBSeedDataTags.json
  • graphSeedDataTags.json

SynTax seedDataTag:

dynamoDBSeedDataTags
graphSeedDataTags

seedData_integrationTest

seeddata s3 for other dev use service,If a developer wants to add more for other important testing purposes, they can add it from the s3 bucket at this point and run batch RefreshSeedData to clean up the seed data in the table after it creates seed data form service deploy and pulls seeddata s3'.

  • How to create folder and sort folder.

regenerateSeedDynamodb

seed data for dynamodb integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase} /mainServcie/regenerateSeedDynamodb/(otherSercie for use db)/{tableName.json}

regenerateSeedGraph

seed data for graph

- nodeConfig

integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase} /mainServcie/regenerateSeedGraph/(other servcie for use graph)/(service graphandler)/(nodeConfig)/{other servie.json}

- relationshipConfig

integrationtest-config-us-east-2/seedData_integrationTest/{dev name}/{testcase} /mainServcie/regenerateSeedGraph/(other servcie for use graph)/(service graphandler)/(relationship)/{other servie.json}

Test config

Create folder

integrationtest-config-us-east-2/test_config/{your folder name}
  • your folder name
1.Create name Developer for folder name inside test_config
2.Create folder service Names of Test
3.Create folder your test
integrationtest-config-us-east-2/test_config/{nameDeveloper}/{serviceNames}/{foldeTest}/
eg. integrationtest-config-us-east-2/test_config/mintDev/complexFilter/basicCase/
4.Can save file events, tests,resources inside

Note: can shared file events, tests,resources by bucket Prefix.

Create file

  • files upload in s3'
-resources.json
-events.json
-tests.json
1.resources.json and events.json is json object
note :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
2.tests.json is json array of objects
  • Detail of files
1.resources.json
2.events.json
  • Syntax; events Syntax
  • If initeage stage snsSqsTrigger is true but not set snsServiceName or snsTopic
-sns
  • set snsSqsTrigger is true, if not set or fase ---> direct invoke
-DirectSqs
  • set BatchSqsMessages is true, if not set or fase ---> direct invoke
  • forStageMatching Use in test important parameter
  • testValueMatches is default true
testValueMatches use in case not test parameter random data eg. timeStamp or uuid , but function require paramiter.
3.tests.json
  • Syntax; tests Syntax
  • Case test dynamodb (optional test) use dynamodbOutputEventIdentifiers in stage of test
  • Upload file to s3
1.batchscript
2.upload to S3 bucket directly

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

  • results of test show in dynamodb table IntTestingTestTestRecord.
  • How to test integrationtest
direct invoke or BashScript

1. direct invoke in console lambda function IntTestingTestInitiateIntegrationTestHdrInv

create params for invoke
{ 
	"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.BashScript integrationTest.sh

Setup seedData

some case much have data before test.In case not own service can be put seedData in bucket s3 and run bashscript "refreshSeedData.sh" for delete old seedData and generate seedData in ownservcie and add on seedData(for use case test) in s3.

  • 1. dynamodb
  • 2. graphHandler
  • 3. bashscript
1.dynamodb
1.1 setting in service
1.1.1 app/__test__/initial_setup/src/ServiceConfig.js
in function tableConfigs
module.exports.tableConfigs = {
  Config: {
    clearDataWhenRefresh: true
  }
}
  • clearDataWhenRefresh set true if want to refresh seed data.
1.1.2 /app/sls_yaml/core-function.yml
Function name RemoveSeedDataDynamo
add role of table want to RemoveSeedData.
3.bashscript

Bash script

upload file to s3

1.create file uploadFileToS3.sh
#!/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
  • run interminal in folder uploadFileToS3.sh

2.run Bash Script

bash uploadFileToS3.sh

test integrationtest

1 create file integrationTest.sh
#!/bin/bash
set -u
stage="Test"
region="us-east-2"
aws configure set region ${region}

declare -a groupTests=(

'{
  "serviceName": "DelivMethodSTD",
  "resourceType": "Lambda",
  "resourceName": "MockDeliveryMethod2GetHdrInv",
  "integrationTestTags": [
    "integrationTest_DelivMethodSTD_Get_NomalCase"
  ],
  "bucketName": "integrationtest-config-us-east-2",
  "bucketPrefix": [
    "test_config/mintDev/DelivMethodSTD/getPassed/",
    "test_config/PluemDev/SharedResource/"
  ]
}'

)

functionName="IntTesting"

for test in "${groupTests[@]}"; do
	echo "start one set of tests"
	echo ${test}
	#... invoke InitateTests....
	aws lambda invoke \
	--function-name "${functionName}${stage}InitiateIntegrationTestHdrInv" \
	--payload "${test}" \
	--invocation-type RequestResponse \
	--cli-binary-format raw-in-base64-out \
	/dev/stdout

	echo "----------- Finish("${functionName}${stage}InitiateIntegrationTestHdrInv") ------------"
done
2 run bashscript
bash integrationTest.sh

refreshSeedData

1.create file bashScript "refreshSeedData.sh"
#!/bin/bash
set -u
declare -a refreshSeedServices=(
"testingMint"
# "DelivMethodSTD"
# ...
)
stage="Test"
region="us-east-2"

payload='{
	"bucketS3":{
		"bucketName":"integrationtest-config-us-east-2",
		"bucketPrefix":["seedData_integrationTest/MintDev/caseTestGenerateSeedData/IntTesting/dynamoDB/",
						"seedData_integrationTest/MintDev/caseTestGenerateSeedDataA/IntTesting/dynamoDB/"
		]
	}
}'
payload="${payload:-{}}"
# Check if the payload is still empty and warn the user
if [ "$payload" == "{}" ]; then
    echo "GenerateSeedData form ownservice"
fi
# -------------------------------------------------------------------------------------------------------
for refreshSeedService in "${refreshSeedServices[@]}"; do
	echo "start refresh seed graph data for ${refreshSeedService}, function name: ${refreshSeedService}${stage}RemoveSeedDataDynamo"

	# refresh seed data dynamodb
	aws lambda invoke \
	--function-name "${refreshSeedService}${stage}RemoveSeedDataDynamo" out\
	--cli-binary-format raw-in-base64-out \
	--region=${region} || continue
done
echo "Finish run all RemoveSeedDataDynamo"

for refreshSeedService in "${refreshSeedServices[@]}"; do
    echo "start refresh seed dynamoDB data for ${refreshSeedService}, function name: ${refreshSeedService}${stage}GenerateSeedDataDynamoTestEnv"
    echo "payload:${payload}"

    aws lambda invoke \
    --function-name "${refreshSeedService}${stage}GenerateSeedDataDynamoTestEnv" out \
    --payload "${payload}" \
    --cli-binary-format raw-in-base64-out \
    --region=${region} || continue
done
echo "Finish run all GenerateSeedDataDynamoTestEnv"
2.run bashscript
bash refreshSeedData.sh

Working documents

Working_documents - Developer guide for making Integration Tests