Skip to content

Commit

Permalink
chore: run tests on linux and windows (#233)
Browse files Browse the repository at this point in the history
* chore: run tests on linux and windows

* pr-fix: update with correct multiple var group

* pr-fix: update with correct array def

* pr-fix: update with correct array def

* pr-fix: update with correct array def

* pr-fix: update with correct array def

* pr-fix: update with strategy in job

* pr-fix: update with strategy in job

* pr-fix: update with allow glober installing ps modules

* pr-fix: update w correct vm image on build

* pr-temp: check windows latest

* pr-fix: don't use variable in strategy.matrix variable definition

* pr-fix: update with `-AllowClobber` on installing dependent ps modules

* pr-fix: update with cross-platform support

* pr-fix: add integration account maps to integration test project

* pr-fix: add sql files to integration test project and prepare for win supoort

* pr-prop: runtime variable declaration

* pr-fix: update release pipeline with runtime vars

* pr-sug: remove try/catch for warming up sql connection

* pr-fix: update with correct sql statement
  • Loading branch information
stijnmoreels authored Nov 30, 2021
1 parent 01a763e commit 2b7e716
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 75 deletions.
15 changes: 11 additions & 4 deletions build/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ stages:
jobs:
- job: Compile
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(Vm.Linux.Image)'
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace package version tokens'
Expand Down Expand Up @@ -75,7 +75,7 @@ stages:
- job: RunUnitTests
displayName: 'Run unit tests'
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(Vm.Linux.Image)'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download build artifacts'
Expand All @@ -93,8 +93,15 @@ stages:
jobs:
- job: RunIntegrationTests
displayName: 'Run integration tests'
strategy:
maxParallel: 1
matrix:
linux:
imageName: ${{ variables['Vm.Linux.Image']}}
windows:
imageName: ${{ variables['Vm.Windows.Image']}}
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(imageName)'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download build artifacts'
Expand All @@ -115,7 +122,7 @@ stages:
- job: PushToMyGet
displayName: 'Push to MyGet'
pool:
vmImage: 'windows-2019'
vmImage: '$(Vm.Linux.Image)'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download build artifacts'
Expand Down
15 changes: 11 additions & 4 deletions build/psgallery-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ stages:
jobs:
- job: Compile
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(Vm.Linux.Image)'
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace package version tokens'
Expand Down Expand Up @@ -79,7 +79,7 @@ stages:
- job: RunUnitTests
displayName: 'Run unit tests'
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(Vm.Linux.Image)'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download build artifacts'
Expand All @@ -97,8 +97,15 @@ stages:
jobs:
- job: RunIntegrationTests
displayName: 'Run integration tests'
strategy:
maxParallel: 1
matrix:
linux:
imageName: ${{ variables['Vm.Linux.Image']}}
windows:
imageName: ${{ variables['Vm.Windows.Image']}}
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(imageName)'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download build artifacts'
Expand All @@ -119,7 +126,7 @@ stages:
- job: PushToNuGet
displayName: 'Push to PowerShell Gallery'
pool:
vmImage: '$(Vm.Image)'
vmImage: '$(Vm.Linux.Image)'
variables:
${{ if ne(variables['Prerelease'], 'none') }}:
Package.Version: "${{ parameters['Package.Version'] }}${{ parameters['Prerelease'] }}"
Expand Down
4 changes: 2 additions & 2 deletions build/templates/run-pester-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ steps:
$content.RequiredModules |
where { $_.ModuleName -ne $null -and $_.ModuleName -notlike 'Arcus.Scripting.*' -and $_.ModuleVersion -ne "#{Package.Version}#" } |
% { Write-Host "Install $($_.ModuleName) module $($_.ModuleVersion)"
Install-Module $_.ModuleName -MaximumVersion $_.ModuleVersion -Force -SkipPublisherCheck } }
Install-Module -Name Az -Force -SkipPublisherCheck -MaximumVersion 5.6.0
Install-Module $_.ModuleName -MaximumVersion $_.ModuleVersion -AllowClobber -Force -SkipPublisherCheck } }
Install-Module -Name Az -Force -AllowClobber -SkipPublisherCheck -MaximumVersion 5.6.0
Install-Module -Name AzTable -Force -SkipPublisherCheck -MaximumVersion 2.1.0
Write-Host "Done installing, start importing modules"
displayName: 'Install Pester test framework and Az required modules'
Expand Down
3 changes: 2 additions & 1 deletion build/variables/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
variables:
DotNet.Sdk.Version: '2.2.105'
Project: 'Arcus.Scripting'
Vm.Image: 'ubuntu-latest'
Vm.Linux.Image: 'ubuntu-latest'
Vm.Windows.Image: 'windows-latest'
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Write-Verbose "Creating Azure Key Vault secret from file..."
$secretValue = $null
if ($Base64) {
Write-Verbose "Use BASE64 format as secret format"
$content = Get-Content $filePath -AsByteStream -Raw
$contentBase64 = [System.Convert]::ToBase64String($content)
$content = Get-Content $filePath -Raw
$bytes = [System.Text.Encoding]::UTF8.GetBytes($content)
$contentBase64 = [System.Convert]::ToBase64String($bytes)
$secretValue = ConvertTo-SecureString -String $contentBase64 -Force -AsPlainText
} else {
$rawContent = Get-Content $FilePath -Raw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = "unexisting-integration-account"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schema = Get-ChildItem($schemaFilePath) -File

# Act
{
Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName -ErrorAction Stop
} | Should -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Set-AzKeyVaultSecret -Times 0
{ Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName -ErrorAction Stop } |
Should -Throw
}
It "Create a single schema in an Integration Account" {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schema = Get-ChildItem($schemaFilePath) -File
$expectedSchemaName = $schema.Name
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -56,7 +51,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schema = Get-ChildItem($schemaFilePath) -File
$expectedSchemaName = $schema.Name
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -82,7 +77,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schema = Get-ChildItem($schemaFilePath) -File
$expectedSchemaName = $schema.BaseName
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -105,7 +100,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd"
$schema = Get-ChildItem($schemaFilePath) -File
$artifactsPrefix = "dev-"
$expectedSchemaName = $artifactsPrefix + $schema.BaseName
Expand All @@ -129,7 +124,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$executionDateTime = (Get-Date).ToUniversalTime()

try {
Expand Down Expand Up @@ -158,7 +153,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$executionDateTime = (Get-Date).ToUniversalTime()

try {
Expand Down Expand Up @@ -187,7 +182,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas"
$artifactsPrefix = "dev-"
$executionDateTime = (Get-Date).ToUniversalTime()

Expand Down Expand Up @@ -219,23 +214,18 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = "unexisting-integration-account"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$map = Get-ChildItem($mapFilePath) -File

# Act
{
Set-AzIntegrationAccountMaps -ResourceGroupName $resourceGroupName -Name $integrationAccountName -MapFilePath $map.FullName -ErrorAction Stop
} | Should -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Set-AzKeyVaultSecret -Times 0
{ Set-AzIntegrationAccountMaps -ResourceGroupName $resourceGroupName -Name $integrationAccountName -MapFilePath $map.FullName -ErrorAction Stop} |
Should -Throw
}
It "Create a single map in an Integration Account" {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$map = Get-ChildItem($mapFilePath) -File
$expectedMapName = $map.Name
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -258,7 +248,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$map = Get-ChildItem($mapFilePath) -File
$expectedMapName = $map.Name
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -284,7 +274,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$map = Get-ChildItem($mapFilePath) -File
$expectedMapName = $map.BaseName
$executionDateTime = (Get-Date).ToUniversalTime()
Expand All @@ -307,7 +297,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$mapFilePath = "$PSScriptRoot\Files\IntegrationAccount\Maps\BankTransfer_CSV-to-BankTransfer_Canonical.xslt"
$map = Get-ChildItem($mapFilePath) -File
$artifactsPrefix = "dev-"
$expectedMapName = $artifactsPrefix + $map.BaseName
Expand All @@ -331,7 +321,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$executionDateTime = (Get-Date).ToUniversalTime()

try {
Expand Down Expand Up @@ -360,7 +350,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$executionDateTime = (Get-Date).ToUniversalTime()

try {
Expand Down Expand Up @@ -389,7 +379,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount {
# Arrange
$resourceGroupName = $config.Arcus.ResourceGroupName
$integrationAccountName = $config.Arcus.IntegrationAccount.Name
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$mapsFolder = "$PSScriptRoot\Files\IntegrationAccount\Maps"
$artifactsPrefix = "dev-"
$executionDateTime = (Get-Date).ToUniversalTime()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@ InModuleScope Arcus.Scripting.KeyVault {
}
}
It "Set secret as BASE64 in Key Vault" {
$contents = [System.Guid]::NewGuid().ToString()
$file = New-Item -Path "test-base64-file.txt" -ItemType File -Value $contents
# Arrange
$expected = [System.Guid]::NewGuid().ToString()
$file = New-Item -Path "test-base64-file.txt" -ItemType File -Value $expected
$secretName = "Arcus-Scripting-KeyVault-MySecret-$([System.Guid]::NewGuid())"
try {
# Arrange
$secretName = "Arcus-Scripting-KeyVault-MySecret-$([System.Guid]::NewGuid())"

# Act
Set-AzKeyVaultSecretAsBase64FromFile -KeyVaultName $config.Arcus.KeyVault.VaultName -SecretName $secretName -FilePath $file.FullName

# Assert
$actual = Get-AzKeyVaultSecret -VaultName $config.Arcus.KeyVault.VaultName -Name $secretName -AsPlainText
[System.Convert]::FromBase64String($actual) |
% { [System.Text.Encoding]::UTF8.GetString($_) } |
Should -Be $contents.ToCharArray()
Should -Be $expected.ToCharArray()
} finally {
Remove-Item -Path $file.FullName
Remove-AzKeyVaultSecret -VaultName $config.Arcus.KeyVault.VaultName -Name $secretName -PassThru -Force
Expand Down Expand Up @@ -71,14 +70,13 @@ InModuleScope Arcus.Scripting.KeyVault {
}
It "Set secret as BASE64 in Key Vault with expiration date" {
# Arrange
$contents = [System.Guid]::NewGuid().ToString()
$file = New-Item -Path "test-file.txt" -ItemType File -Value $contents
$expected = [System.Guid]::NewGuid().ToString()
$file = New-Item -Path "test-base64-file.txt" -ItemType File -Value $expected
$secretName = "Arcus-Scripting-KeyVault-MySecret-$([System.Guid]::NewGuid())"
$expirationDate = (Get-Date).AddDays(7).ToUniversalTime()
$expirationDate = $expirationDate.AddTicks(-$expirationDate.Ticks)

try
{
try {
# Act
Set-AzKeyVaultSecretAsBase64FromFile -KeyVaultName $config.Arcus.KeyVault.VaultName -SecretName $secretName -Expires $expirationDate -FilePath $file.FullName

Expand All @@ -88,7 +86,7 @@ InModuleScope Arcus.Scripting.KeyVault {
$actual = Get-AzKeyVaultSecret -VaultName $config.Arcus.KeyVault.VaultName -Name $secretName -AsPlainText
[System.Convert]::FromBase64String($actual) |
% { [System.Text.Encoding]::UTF8.GetString($_) } |
Should -Be $contents.ToCharArray()
Should -Be $expected.ToCharArray()

} finally {
Remove-Item -Path $file.FullName
Expand Down
Loading

0 comments on commit 2b7e716

Please sign in to comment.