Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add functional test to check bot deployed answer #919

Merged
merged 24 commits into from
Jun 12, 2019

Conversation

Bill7zz
Copy link
Contributor

@Bill7zz Bill7zz commented May 9, 2019

Proposed Changes

Add functional test to send and receive messages to bot deployed in Azure.

Description

In this pull request, we added a new functional test to check an answer from a bot deployed in Azure.
To run the test is necessary to configure a pipeline that Deploys a bot in Azure and create a Direct Line channel to connect it.

Steps to configure the pipeline

Created a new pipeline and connect with the branch that runs a the functional test.

  1. Define the following environment variables: TestBotAppId, TestBotAppSecret, TestBotName and mark them as secret.
    image

Note: You can create those variables by entering on the Application Registration Portal.

  1. Add the Azure Resource Group Deployment task to create the Bot Resource Group, by filling the Resource group's name and adding the Template's URL: 'libraries/testbot/template/windows/template.json'
    image

Note: You need to add an Azure Resource Manager service connection.

  1. Click on “…” next to the Override Parameters textbox and complete the field we highlighted on the image bellow (serverfarmName, siteName, appId, appSecret and botId) using quotation marks.

image

You can find the autocompleted field below:
image

  1. Add the Azure CLI task to generate the web.config file necessary to deploy a bot source code to Azure. Configure the task with an Azure subscription and the script inline options.
    image

The script looks likes:
call az bot prepare-deploy --code-dir "$(System.DefaultWorkingDirectory)/libraries/testbot" --lang Javascript

  1. Add the PowerShell task to compress the bot source code. Configure the task with the 'Inline' script option. In this task, exclude the node_modules, template, and deployment-scripts folder.
    image

The script looks likes:

move-item -path $(System.DefaultWorkingDirectory)/libraries/testbot/deployment-scripts/windows/* -destination $(System.DefaultWorkingDirectory)/libraries/testbot

$DirToCompress = "$(System.DefaultWorkingDirectory)/libraries/testbot"
$DirtoExclude =@("node_modules", "template, deployment-scripts")
$files = Get-ChildItem -Path $DirToCompress -Exclude $DirtoExclude
$ZipFileResult ="$(System.DefaultWorkingDirectory)/libraries/testbot/testbot.zip"
Compress-Archive -Path $files -DestinationPath $ZipFileResult
  1. Add the Azure CLI task task to deploy the bot zip file and connect it to the DirectLine channel. The output with the secret key goes into a .json file. We will use this key to start a conversation with the bot in the test logic.
    image

The script looks likes:

call az webapp deployment source config-zip --resource-group "$(TestBotName)" --name "$(TestBotName)" --src "$(System.DefaultWorkingDirectory)/libraries/testbot/testbot.zip"

call az bot directline create -n "$(TestBotName)" -g "$(TestBotName)" > "$(System.DefaultWorkingDirectory)/libraries/testbot/DirectLineCreate.json"
  1. Add the PowerShell task to read the .json file generated in the previous step and get the secret key to connect to the bot.

image

The script looks likes:

$json = Get-Content '$(System.DefaultWorkingDirectory)\libraries\testbot\DirectLineCreate.json' | Out-String | ConvertFrom-Json

$key = $json.properties.properties.sites.key

echo "##vso[task.setvariable variable=DIRECT_LINE_KEY;]$key"
  1. Configure the Pipeline to run the functional-tests
  • Add Node task.
    • Node version 10x
  • Add NPM install task
    • Use the default options
  • Add NPM Custom command task
    • Run the functional-test command
      image
  1. After the Tests run, add a new Azure CLI Task to delete the resource group we've created.
    image

The script looks likes:
call az group delete -n "$(TestBotName)" --yes

We strongly recommend setting this task to run even if any of the previous tasks have failed or the build has been canceled. With this setting, we will ensure that the resources will be deleted from Azure even if the build fails at any step.

Testing

We configured and ran a Build Pipeline to test the steps guide and the functional test logic. The result can be seen in the image below.
image

@coveralls
Copy link

coveralls commented May 9, 2019

Pull Request Test Coverage Report for Build 60136

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.737%

Totals Coverage Status
Change from base Build 59683: 0.0%
Covered Lines: 3257
Relevant Lines: 3663

💛 - Coveralls

@Bill7zz Bill7zz force-pushed the feature/functional-test-bot branch from d8b7425 to f80e0af Compare May 9, 2019 21:04
@Bill7zz Bill7zz force-pushed the feature/functional-test-bot branch from 0682401 to 5e644fd Compare May 21, 2019 14:37
@ParadoxARG ParadoxARG merged commit 99eb0a2 into master Jun 12, 2019
@ceciliaavila ceciliaavila deleted the feature/functional-test-bot branch June 13, 2019 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants