Skip to content

Commit

Permalink
Add test job
Browse files Browse the repository at this point in the history
  • Loading branch information
Recep Ozkurt committed Dec 18, 2023
1 parent af54b1b commit f05cc14
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
runs-on: ubuntu-latest
environment: Website
needs: preview
outputs:
appServiceAppHostName: ${{ steps.deploy.outputs.appServiceAppHostName }}
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
Expand All @@ -72,10 +74,25 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: azure/arm-deploy@v1
id: deploy
name: Deploy website
with:
failOnStdErr: false
deploymentName: ${{ github.run_number }}
resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }}
template: ./deploy/main.bicep
parameters: environmentType=${{ env.ENVIRONMENT_TYPE }}
smoke-test:
runs-on: ubuntu-latest
needs: deploy
steps:
- uses: actions/checkout@v3
- run: |
$container = New-PesterContainer `
-Path 'deploy/Website.Tests.ps1' `
-Data @{ HostName = '${{needs.deploy.outputs.appServiceAppHostName}}' }
Invoke-Pester `
-Container $container `
-CI
name: Run smoke tests
shell: pwsh
23 changes: 23 additions & 0 deletions deploy/Website.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $HostName
)

Describe 'Toy Website' {

It 'Serves pages over HTTPS' {
$request = [System.Net.WebRequest]::Create("https://$HostName/")
$request.AllowAutoRedirect = $false
$request.GetResponse().StatusCode |
Should -Be 200 -Because "the website requires HTTPS"
}

It 'Does not serves pages over HTTP' {
$request = [System.Net.WebRequest]::Create("http://$HostName/")
$request.AllowAutoRedirect = $false
$request.GetResponse().StatusCode |
Should -BeGreaterOrEqual 300 -Because "HTTP is not secure"
}

}

0 comments on commit f05cc14

Please sign in to comment.