Skip to content

Commit

Permalink
[SELC-5980] Postman collection for integration test (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu authored Nov 13, 2024
1 parent 3000bf0 commit 68c4f0f
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 55 deletions.
94 changes: 39 additions & 55 deletions .github/workflows/call_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,45 @@ on:
required: true
description: add '-pnpg' if workflow is related to pnpg

variables:
postmanEnvFile: integration_environment

# ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/uat') }}:
# # selfHostedAgentPool: $(UAT_AGENT_POOL)

jobs:
test:
environment: ${{ inputs.environment }}-ci
name: 'Run Postman collection on ${{ inputs.environment }}'
runs-on: ubuntu-20.04
# pool:
# name: $(selfHostedAgentPool)
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout
- name: 'Download postman environment'
env:
INTEGRATION_ENVIRONMENT: ${{ secrets.INTEGRATION_ENVIRONMENT }}
run: 'echo "$INTEGRATION_ENVIRONMENT" | base64 --decode > Selfcare-Integration.postman_environment.json'
shell: bash
- name: 'List file'
run: 'ls -la'
shell: bash
- name: 'Cat file'
run: 'cat Selfcare-Integration.postman_environment.json'
shell: bash
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
with:
node-version: '16.x'

# ${{ else }}:
# # selfHostedAgentPool: $(DEV_AGENT_POOL)
# postmanEnvFile: integration_environment.json
- name: Install newman
shell: bash
run: npm install -g newman

- name: Run newman
shell: bash
run: newman run ./test/newman/Selfcare-Integration.postman_collection.json -e Selfcare-Integration.postman_environment.json --reporters cli,json --reporter-json-export ./test/test-result.json

stages:
- stage: stage_postman_test
environment: ${{ inputs.environment }}-ci
displayName: 'Test_e2e_on_${{ variables.environment }}'
dependsOn: [ stage_deploy ]
condition: and(succeeded(),or(eq(variables.environment, 'DEV'), eq(variables.environment, 'UAT')))
jobs:
- job: 'Run_Postman_collection_on_${{ variables.environment }}'
displayName: 'Run Postman collection on ${{ variables.environment }}'
# pool:
# name: $(selfHostedAgentPool)
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
- task: Npm@1
displayName: Install newman
inputs:
command: custom
customCommand: install -g newman
- task: DownloadSecureFile@1
displayName: 'download postman environment'
name: postman_env
inputs:
secureFile: $(postmanEnvFile)
- task: CmdLine@2
displayName: Run newman
continueOnError: true # Useful to avoid the skipping of result publishing task
inputs:
script: newman run selfcare-onboarding/test/newman/Selfcare-Integration.postman_collection.json -e $(postman_env.secureFilePath) --reporters cli,junit --reporter-junit-export result/test-result.xml
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/test-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/result/'
testRunTitle: 'Publish Newman Test Results'
# - task: 'Bash@3'
# displayName: 'Send message on Slack'
# condition: in(variables['Agent.JobStatus'], 'SucceededWithIssues', 'Failed')
# inputs:
# targetType: 'inline'
# script: >
# curl -X POST \
# -H "Content-type: application/json" \
# --data '{"text": "*Attention: There is an error in pipeline $(System.DefinitionName) in step _postman test_!*\nCheck the logs for more details $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) to view the build results."}' \
# $(SLACK_WEBHOOK_URL)
- name: Send newman report
shell: bash
run: node ./test/convert.js

- name: 'Send message on Slack'
shell: bash
run: >
curl -X POST ${{ secrets.SLACK_WEBHOOK_URL }} -H 'Content-type: application/json' -d @test/stats.json
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ override.tf
override.tf.json
*_override.tf
*_override.tf.json

**/node_modules/*
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"axios": "^1.7.7"
}
}
75 changes: 75 additions & 0 deletions test/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var fs = require('fs');

fs.readFile('test/test-result.json', 'utf8', function (err, data) {
if (err) throw err; // we'll not consider error handling for now
var obj = JSON.parse(data);

let json = JSON.stringify(convert(obj["run"]["stats"], process.argv[2]));
fs.writeFile("test/stats.json", json, 'utf8', (err) => {
if (err) {
console.error('Error writing to file', err);
} else {
console.log('Data written to file');
}
});
});


function convert(payload) {
var block =
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:white_check_mark: GitHub Actions*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Iterations*:\ntotal: "+payload["iterations"]["total"]+" pending: "+payload["iterations"]["pending"]+" failed: "+payload["iterations"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Items*:\ntotal: "+payload["items"]["total"]+" pending: "+payload["items"]["pending"]+" failed: "+payload["items"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Scripts*:\ntotal: "+payload["scripts"]["total"]+" pending: "+payload["scripts"]["pending"]+" failed: "+payload["scripts"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Prerequests*:\ntotal: "+payload["prerequests"]["total"]+" pending: "+payload["prerequests"]["pending"]+" failed: "+payload["prerequests"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Requests*:\ntotal: "+payload["requests"]["total"]+" pending: "+payload["requests"]["pending"]+" failed: "+payload["requests"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Tests*:\ntotal: "+payload["tests"]["total"]+" pending: "+payload["tests"]["pending"]+" failed: "+payload["tests"]["failed"]
},
{
"type": "mrkdwn",
"text": "*Assertions*:\ntotal: "+payload["assertions"]["total"]+" pending: "+payload["assertions"]["pending"]+" failed: "+payload["assertions"]["failed"]
},
{
"type": "mrkdwn",
"text": "*TestScripts*:\ntotal: "+payload["testScripts"]["total"]+" pending: "+payload["testScripts"]["pending"]+" failed: "+payload["testScripts"]["failed"]
},
{
"type": "mrkdwn",
"text": "*PrerequestScripts*:\ntotal: "+payload["prerequestScripts"]["total"]+" pending: "+payload["prerequestScripts"]["pending"]+" failed: "+payload["prerequestScripts"]["failed"]
},
]
}
]
}

return block
}

51 changes: 51 additions & 0 deletions test/newman/Selfcare-Integration.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,57 @@
{
"name": "External",
"item": [
{
"name": "getUserGroup",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"getInstitutionUsersByProduct ok\", function () {",
"var jsonData = pm.response.json();",
"pm.response.to.have.status(200);",
"//pm.expect(jsonData.message).to.contain('Entity created');",
"});"
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Ocp-Apim-Subscription-Key",
"value": "{{apimKeyPN}}",
"type": "text"
}
],
"url": {
"raw": "{{apiBaseUrl}}/external/v2/user-groups?userId={{userId}}&institutions={{institutionId}}",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"external",
"v2",
"user-groups"
],
"query": [
{
"key": "userId",
"value": "{{userId}}"
},
{
"key": "institutions",
"value": "{{institutionId}}"
}
]
}
},
"response": []
},
{
"name": "getInstitutionUsersByProduct",
"event": [
Expand Down

0 comments on commit 68c4f0f

Please sign in to comment.