Skip to content

Commit

Permalink
Add functional test pipeline for Facebook secondary test bot (#5949)
Browse files Browse the repository at this point in the history
* Add pipeline for secondary FB test bot.

* Switch to using primary ARM templates.

* Fix test to accept "Echo Secondary"

* Improve test message

* Test message tweak

* Add Sleep 1 minute to test secondary

* Tweak display names

* Cleanup

* Cleanup 2
  • Loading branch information
BruceHaley authored Nov 8, 2021
1 parent 6f4c6cd commit ada2477
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public async Task SendAndReceiveFacebookMessageShouldSucceed()

var response = await ReceiveMessageAsync();

Assert.AreEqual($"Echo: {echoGuid}", response);
//Accept response from either primary or secondary test bot.
Assert.IsTrue(
response.Equals($"Echo: {echoGuid}") || response.Equals($"Echo Secondary: {echoGuid}"),
$"Expected:<Echo...{echoGuid}>. Actual:<{response}>.");
}

private async Task SendMessageAsync(string echoGuid)
Expand Down
186 changes: 186 additions & 0 deletions build/yaml/botbuilder-dotnet-ci-facebook-test-secondary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#
# Runs functional tests against the Facebook channel.
#

# "name" here defines the build number format. Build number is accessed via $(Build.BuildNumber)
name: $(Build.BuildId)

pool:
vmImage: $[ coalesce( variables['VMImage'], 'windows-2019' ) ] # or 'windows-latest' or 'vs2017-win2016'

trigger: # ci trigger
batch: true
branches:
include:
- main
paths:
include:
- '*'
exclude:
- doc/
- specs/
- Changes.md
- LICENSE
- README.md
- UsingMyGet.md

pr: # pr trigger
branches:
include:
- main
paths:
include:
- build/yaml/botbuilder-dotnet-ci-facebook-test.yml

variables:
AppId: $(FacebookTestBotAppId)
AppSecret: $(FacebookTestBotAppSecret)
BotGroup: $(FacebookTestBotBotGroup)
BotName: $(FacebookTestBotBotName)
BuildPlatform: 'any cpu'
BuildConfiguration: 'debug'
MSBuildArguments: -p:SignAssembly=false -p:delaySign=false -p:RunAnalyzersDuringBuild=false
Parameters.solution: Microsoft.Bot.Builder.sln
runCodesignValidationInjection: false # Disables unnecessary CodeSign Validation step
skipComponentGovernanceDetection: true # Disables unnecessary Component Governanace Detection step
SolutionDir: $(System.DefaultWorkingDirectory) # Consumed in dotnet publish by Directory.Build.props and a few test projects.
# FacebookTestBotAppId: define this in Azure
# FacebookTestBotAppSecret: define this in Azure
# AzureSubscription: define this in Azure
# DeleteResourceGroup: (optional) define this in Azure. Default = true.
# FacebookTestBotBotGroup: define this in Azure
# FacebookTestBotBotName: define this in Azure
# FacebookTestBotFacebookAccessToken: define this in Azure
# FacebookTestBotFacebookAppSecret: define this in Azure
# FacebookTestBotFacebookVerifyToken: (optional) define this in Azure. Useful for webhook testing for un-deleted resources post-execution.
# FacebookTestBotSenderId: define this in Azure?: This var not needed in build 156862. Revisit this after the build's test is fixed & running.

steps:
- powershell: 'gci env:* | sort-object name | Format-Table -AutoSize -Wrap'
displayName: 'Display env vars'

- powershell: |
# Create DateTimeTag for Resource Group
$DateTimeTag=Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"
"##vso[task.setvariable variable=DateTimeTag]$DateTimeTag";
displayName: 'Create DateTimeTag for Resource Group'
# Get-Date on Azure DevOps returns a datetime relative to UTC-0, so "Z" is being used instead of the dynamic "K".

- powershell: |
$InvalidVariables = $FALSE
$Message = "Required variable 'REPLACE_VARIABLE' either null, empty or whitespaced. Please set up this variable in the pipeline configuration."
if(!"$(FacebookTestBotAppId)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotAppId")}
if(!"$(FacebookTestBotAppSecret)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotAppSecret")}
if(!"$(AzureSubscription)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "AzureSubscription")}
if(!"$(FacebookTestBotBotGroup)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotBotGroup")}
if(!"$(FacebookTestBotBotName)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotBotName")}
if(!"$(FacebookTestBotFacebookAccessToken)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotFacebookAccessToken")}
if(!"$(FacebookTestBotFacebookAppSecret)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotFacebookAppSecret)")}
if(!"$(FacebookTestBotSenderId)".Trim()) {$InvalidVariables = $TRUE; Write-Host $Message.replace("REPLACE_VARIABLE", "FacebookTestBotSenderId")}
if($InvalidVariables){
Write-Host "##vso[task.setvariable variable=InvalidVariables;]true"
Write-Host "##vso[task.complete result=Failed;]DONE"
}
displayName: Validate variables

- powershell: |
# Set values in appsettings.json file.
$file = "$(Build.SourcesDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.SecondaryTestBot\appsettings.json";
$content = Get-Content -Raw $file | ConvertFrom-Json;
$content.FacebookVerifyToken = "$(FacebookTestBotFacebookVerifyToken)";
$content.FacebookAppSecret = "$(FacebookTestBotFaceBookAppSecret)";
$content.FacebookAccessToken = "$(FacebookTestBotFacebookAccessToken)";
$content | ConvertTo-Json | Set-Content $file;
displayName: 'Set values in appsettings.json file.'
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
verbosityRestore: 'Detailed'

- task: DotNetCoreCLI@2
displayName: 'dotnet publish secondarytestbot'
inputs:
command: publish
publishWebProjects: false
projects: '$(System.DefaultWorkingDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.SecondaryTestBot\Microsoft.Bot.Builder.Adapters.Facebook.SecondaryTestBot.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(System.DefaultWorkingDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.SecondaryTestBot\PublishedBot -p:TreatWarningsAsErrors=false -p:RestoreUseSkipNonexistentTargets=false'
modifyOutputPath: false

- task: AzureCLI@2
displayName: 'Preexisting RG: create Azure resources. Runs in even builds.'
inputs:
azureSubscription: $(AzureSubscription)
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
Write-Host "`n***** Creating Azure resources using the preexisting-rg template *****";
Write-Host "This task runs for even-numbered builds. Build ID = $(Build.BuildId)";
Write-Host "************************************************************************";
Set-PSDebug -Trace 1;
az group create --location westus --name $(BotGroup) --tags buildName="$(Build.DefinitionName)" cause=automation date="$(DateTimeTag)" product="$(Build.Repository.Name)" sourceBranch="$(Build.SourceBranch)";
# set up bot channels registration, app service, app service plan
az deployment group create --resource-group "$(BotGroup)" --template-file "$(System.DefaultWorkingDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.PrimaryTestBot\DeploymentTemplates\template-with-preexisting-rg.json" --parameters appId="$(AppId)" appSecret="$(AppSecret)" botId="$(BotName)" botSku=F0 newAppServicePlanName="$(BotName)" newWebAppName="$(BotName)" appServicePlanLocation="westus" facebookVerifyToken="$(FacebookTestBotFacebookVerifyToken)" facebookAppSecret="$(FacebookTestBotFaceBookAppSecret)" facebookAccessToken="$(FacebookTestBotFacebookAccessToken)" --name "$(BotName)";
Set-PSDebug -Trace 0;
condition: and(succeeded(), or( endsWith(variables['Build.BuildId'], 0), endsWith(variables['Build.BuildId'], 2), endsWith(variables['Build.BuildId'], 4), endsWith(variables['Build.BuildId'], 6), endsWith(variables['Build.BuildId'], 8)))

- task: AzureCLI@2
displayName: 'New RG: create Azure resources. Runs in odd builds.'
inputs:
azureSubscription: $(AzureSubscription)
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
Write-Host "`n***** Creating Azure resources using the new-rg template *****";
Write-Host "This task runs for odd-numbered builds. Build ID = $(Build.BuildId)";
Write-Host "****************************************************************";
Set-PSDebug -Trace 1;
# set up resource group, bot channels registration, app service, app service plan
az deployment sub create --name "$(BotGroup)" --template-file "$(System.DefaultWorkingDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.PrimaryTestBot\DeploymentTemplates\template-with-new-rg.json" --location "westus" --parameters appId=$(AppId) appSecret="$(AppSecret)" botId="$(BotName)" botSku=F0 newAppServicePlanName="$(BotName)" newWebAppName="$(BotName)" groupName="$(BotGroup)" groupLocation="westus" newAppServicePlanLocation="westus" facebookVerifyToken="$(FacebookTestBotFacebookVerifyToken)" facebookAppSecret="$(FacebookTestBotFaceBookAppSecret)" facebookAccessToken="$(FacebookTestBotFacebookAccessToken)" groupTags='{\"buildName\":\"$(Build.DefinitionName)\", \"cause\":\"automation\", \"date\":\"$(DateTimeTag)\", \"product\":\"$(Build.Repository.Name)\", \"sourceBranch\":\"$(Build.SourceBranch)\"}';
Set-PSDebug -Trace 0;
condition: and(succeeded(), or( endsWith(variables['Build.BuildId'], 1), endsWith(variables['Build.BuildId'], 3), endsWith(variables['Build.BuildId'], 5), endsWith(variables['Build.BuildId'], 7), endsWith(variables['Build.BuildId'], 9)))

- task: AzureCLI@1
displayName: 'Deploy the bot'
inputs:
azureSubscription: $(AzureSubscription)
scriptLocation: inlineScript
inlineScript: |
call az webapp deployment source config-zip --resource-group "$(BotGroup)" --name "$(BotName)" --src "$(System.DefaultWorkingDirectory)\tests\Adapters\Microsoft.Bot.Builder.Adapters.Facebook.SecondaryTestBot\PublishedBot\PublishedBot.zip"
- powershell: |
Start-Sleep -Seconds 60
displayName: 'Sleep 1 minute for bot to settle'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: test
projects: '$(System.DefaultWorkingDirectory)\FunctionalTests\Microsoft.Bot.Builder.FunctionalTests\Microsoft.Bot.Builder.FunctionalTests.csproj'
arguments: '-v n --configuration $(BuildConfiguration) --filter FacebookChatTest'
env:
BOT_ENDPOINT: https://$(BotName).azurewebsites.net/api/messages
FacebookTestBotFacebookAccessToken: $(FacebookTestBotFacebookAccessToken)
FacebookTestBotFacebookAppSecret: $(FacebookTestBotFacebookAppSecret)
FacebookTestBotSenderId: $(FacebookTestBotSenderId)

- task: AzureCLI@1
displayName: 'Delete Azure resources'
inputs:
azureSubscription: '$(AzureSubscription)'
scriptLocation: inlineScript
inlineScript: 'call az group delete -n "$(BotGroup)" --yes'
condition: and(always(), ne(variables['DeleteResourceGroup'], 'false'), ne(variables.InvalidVariables, 'true'))

- script: |
cd ..
dir *.* /s
displayName: 'Dir workspace'
continueOnError: true
condition: succeededOrFailed()
2 changes: 1 addition & 1 deletion build/yaml/botbuilder-dotnet-ci-facebook-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ steps:
verbosityRestore: 'Detailed'

- task: DotNetCoreCLI@2
displayName: 'dotnet publish testbot'
displayName: 'dotnet publish primarytestbot'
inputs:
command: publish
publishWebProjects: false
Expand Down

0 comments on commit ada2477

Please sign in to comment.