From f17bb5b4fe6b6718103b6142f96b6b376bec6c70 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:10:29 +0200 Subject: [PATCH 01/11] use separate tasks for tests --- build/ci-build.yml | 123 ++++++++++++------ build/psgallery-release.yml | 123 ++++++++++++------ build/templates/run-pester-tests.yml | 3 +- ...Arcus.Scripting.ActiveDirectory.tests.ps1} | 0 .../Arcus.Scripting.Tests.Unit.pssproj | 2 +- 5 files changed, 163 insertions(+), 88 deletions(-) rename src/Arcus.Scripting.Tests.Unit/{Arcus.Scripting.ActiveDirectory.ps1 => Arcus.Scripting.ActiveDirectory.tests.ps1} (100%) diff --git a/build/ci-build.yml b/build/ci-build.yml index 74d99178..6b1ff219 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -18,6 +18,39 @@ parameters: - name: 'Package.Version.ManualTrigger' type: string default: 'preview' + - name: 'UnitTests' + type: object + default: + - name: ActiveDirectory + - name: ApiManagement + - name: AppService + - name: DataFactory + - name: DevOps + - name: IntegrationAccount + - name: KeyVault + - name: LogicApps + - name: Management + - name: Security + - name: Sql + - name: Storage.Blob + - name: Storage.FileShare + - name: Storage.Table + - name: 'IntegrationTests' + type: object + default: + - name: ActiveDirectory + - name: AppService + - name: ARM + - name: DevOps + - name: IntegrationAccount + - name: KeyVault + - name: LogicApps + - name: Management + - name: Security + - name: Sql + - name: Storage.Blob + - name: Storage.FileShare + - name: Storage.Table resources: repositories: @@ -58,50 +91,54 @@ stages: targetPath: '$(Pipeline.Workspace)/build' artifactName: Build - - stage: UnitTests - displayName: Unit Tests - dependsOn: Build - condition: succeeded() - jobs: - - job: RunUnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Linux.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Unit' + - ${{ each UnitTest in parameters.UnitTests }}: + - stage: UnitTests_${{UnitTest.name}} + displayName: Unit Tests - ${{UnitTest.name}} + dependsOn: Build + condition: succeeded() + jobs: + - job: RunUnitTests + displayName: 'Run unit tests' + pool: + vmImage: '$(Vm.Linux.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Unit' + testName: '$(Project).${{UnitTest.name}}' - - stage: IntegrationTests - displayName: Integration Tests - dependsOn: Build - condition: succeeded() - 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: '$(imageName)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Integration' + - ${{ each IntegrationTest in parameters.IntegrationTests }}: + - stage: IntegrationTests_${{IntegrationTest.name}} + displayName: Integration Tests - ${{IntegrationTest.name}} + dependsOn: Build + condition: succeeded() + 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: '$(imageName)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Integration' + testName: '$(Project).${{IntegrationTest.name}}' - stage: ReleaseToMyget displayName: 'Release to MyGet' diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index 2fc71e2c..c560d4f2 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -10,6 +10,39 @@ parameters: displayName: 'Prerelease string (ex. -alpha, -alpha1, -BETA, -update20171020) or none' type: 'string' default: 'none' + - name: 'UnitTests' + type: object + default: + - name: ActiveDirectory + - name: ApiManagement + - name: AppService + - name: DataFactory + - name: DevOps + - name: IntegrationAccount + - name: KeyVault + - name: LogicApps + - name: Management + - name: Security + - name: Sql + - name: Storage.Blob + - name: Storage.FileShare + - name: Storage.Table + - name: 'IntegrationTests' + type: object + default: + - name: ActiveDirectory + - name: AppService + - name: ARM + - name: DevOps + - name: IntegrationAccount + - name: KeyVault + - name: LogicApps + - name: Management + - name: Security + - name: Sql + - name: Storage.Blob + - name: Storage.FileShare + - name: Storage.Table resources: repositories: @@ -51,50 +84,54 @@ stages: targetPath: '$(Pipeline.Workspace)/build' artifactName: Build - - stage: UnitTests - displayName: Unit Tests - dependsOn: Build - condition: succeeded() - jobs: - - job: RunUnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Linux.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Unit' + - ${{ each UnitTest in parameters.UnitTests }}: + - stage: UnitTests_${{UnitTest.name}} + displayName: Unit Tests - ${{UnitTest.name}} + dependsOn: Build + condition: succeeded() + jobs: + - job: RunUnitTests + displayName: 'Run unit tests' + pool: + vmImage: '$(Vm.Linux.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Unit' + testName: '$(Project).${{UnitTest.name}}' - - stage: IntegrationTests - displayName: Integration Tests - dependsOn: Build - condition: succeeded() - 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: '$(imageName)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Integration' + - ${{ each IntegrationTest in parameters.IntegrationTests }}: + - stage: IntegrationTests_${{IntegrationTest.name}} + displayName: Integration Tests - ${{IntegrationTest.name}} + dependsOn: Build + condition: succeeded() + 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: '$(imageName)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Integration' + testName: '$(Project).${{IntegrationTest.name}}' - stage: Release displayName: 'Release to PowerShell Gallery' diff --git a/build/templates/run-pester-tests.yml b/build/templates/run-pester-tests.yml index bc922b5e..d9255ab7 100644 --- a/build/templates/run-pester-tests.yml +++ b/build/templates/run-pester-tests.yml @@ -1,5 +1,6 @@ parameters: projectName: '' + testName: '' steps: - pwsh: 'wget -O - https://aka.ms/install-powershell.sh | sudo bash' @@ -48,7 +49,7 @@ steps: Get-ChildItem -Path ./src -Filter *.psm1 -Recurse -Exclude "*Arcus.Scripting.Security*", "*.All.psm1" | % { Write-Host "Import $($_.DirectoryName) module" Import-Module -Name $_.DirectoryName -ErrorAction Stop } - Invoke-Pester -Script "./src/${{ parameters.projectName }}/" -OutputFile "./pester.test.results.xml" -OutputFormat 'NUnitXML' -EnableExit + Invoke-Pester -Script "./src/${{ parameters.projectName }}/${{ parameters.testName }}.tests.ps1" -OutputFile "./pester.test.results.${{ parameters.testName }}.xml" -OutputFormat 'NUnitXML' -EnableExit displayName: 'Run Pester tests' failOnStderr: true env: diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 similarity index 100% rename from src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.ps1 rename to src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj index 6a8ee8f1..f8ff3b99 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj @@ -76,7 +76,7 @@ - + From b29536a7995b0596df61e4efa001ddc865390806 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:17:20 +0200 Subject: [PATCH 02/11] fix stage names --- build/ci-build.yml | 4 ++-- build/psgallery-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 6b1ff219..eddd745d 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -92,7 +92,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{UnitTest.name}} + - stage: UnitTests_[replace(${{UnitTest.name}}, '.', '_')] displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -113,7 +113,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{IntegrationTest.name}} + - stage: IntegrationTests_[replace(${{IntegrationTest.name}}, '.', '_')] displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index c560d4f2..c9b944b9 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -85,7 +85,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{UnitTest.name}} + - stage: UnitTests_[replace(${{UnitTest.name}}, '.', '_')] displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -106,7 +106,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{IntegrationTest.name}} + - stage: IntegrationTests_[replace(${{IntegrationTest.name}}, '.', '_')] displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() From 836e1d94306b7657d211aa3fff7dea1cdc31a039 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:18:44 +0200 Subject: [PATCH 03/11] fix stage names part 2 --- build/ci-build.yml | 4 ++-- build/psgallery-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index eddd745d..152a1e72 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -92,7 +92,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_[replace(${{UnitTest.name}}, '.', '_')] + - stage: UnitTests_$[replace(${{UnitTest.name}}, '.', '_')] displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -113,7 +113,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_[replace(${{IntegrationTest.name}}, '.', '_')] + - stage: IntegrationTests_$[replace(${{IntegrationTest.name}}, '.', '_')] displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index c9b944b9..f6037874 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -85,7 +85,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_[replace(${{UnitTest.name}}, '.', '_')] + - stage: UnitTests_$[replace(${{UnitTest.name}}, '.', '_')] displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -106,7 +106,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_[replace(${{IntegrationTest.name}}, '.', '_')] + - stage: IntegrationTests_$[replace(${{IntegrationTest.name}}, '.', '_')] displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() From 8e22bddb33ea12531d8b7475d932024501928e76 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:23:58 +0200 Subject: [PATCH 04/11] fix stage names part 3 --- build/ci-build.yml | 4 ++-- build/psgallery-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 152a1e72..0a025973 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -92,7 +92,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_$[replace(${{UnitTest.name}}, '.', '_')] + - stage: UnitTests_${{replace(UnitTest, '.', '_')}} displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -113,7 +113,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_$[replace(${{IntegrationTest.name}}, '.', '_')] + - stage: IntegrationTests_${{replace(IntegrationTest, '.', '_')}} displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index f6037874..5a5271fa 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -85,7 +85,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_$[replace(${{UnitTest.name}}, '.', '_')] + - stage: UnitTests_${{replace(UnitTest, '.', '_')}} displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -106,7 +106,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_$[replace(${{IntegrationTest.name}}, '.', '_')] + - stage: IntegrationTests_${{replace(IntegrationTest, '.', '_')}} displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() From 1f66158939cd33ef6e5618a0c3f62a9e42439238 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:25:38 +0200 Subject: [PATCH 05/11] fix stage names part 4 --- build/ci-build.yml | 4 ++-- build/psgallery-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 0a025973..653e7c78 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -92,7 +92,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{replace(UnitTest, '.', '_')}} + - stage: UnitTests_${{replace(UnitTest.name, '.', '_')}} displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -113,7 +113,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{replace(IntegrationTest, '.', '_')}} + - stage: IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index 5a5271fa..a49790fb 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -85,7 +85,7 @@ stages: artifactName: Build - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{replace(UnitTest, '.', '_')}} + - stage: UnitTests_${{replace(UnitTest.name, '.', '_')}} displayName: Unit Tests - ${{UnitTest.name}} dependsOn: Build condition: succeeded() @@ -106,7 +106,7 @@ stages: testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{replace(IntegrationTest, '.', '_')}} + - stage: IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} displayName: Integration Tests - ${{IntegrationTest.name}} dependsOn: Build condition: succeeded() From c528531a1b2762d6cf09c82da596d4fe5d0930bf Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:28:15 +0200 Subject: [PATCH 06/11] fix dependson --- build/ci-build.yml | 6 ++++-- build/psgallery-release.yml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 653e7c78..e115f542 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -143,8 +143,10 @@ stages: - stage: ReleaseToMyget displayName: 'Release to MyGet' dependsOn: - - UnitTests - - IntegrationTests + - ${{ each each UnitTest in parameters.UnitTests }}: + - UnitTests_${{replace(UnitTest.name, '.', '_')}} + - ${{ each each IntegrationTest in parameters.IntegrationTests }}: + - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} condition: succeeded() jobs: - job: PushToMyGet diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index a49790fb..cb4009d9 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -136,8 +136,10 @@ stages: - stage: Release displayName: 'Release to PowerShell Gallery' dependsOn: - - UnitTests - - IntegrationTests + - ${{ each each UnitTest in parameters.UnitTests }}: + - UnitTests_${{replace(UnitTest.name, '.', '_')}} + - ${{ each each IntegrationTest in parameters.IntegrationTests }}: + - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} condition: succeeded() jobs: - job: PushToNuGet From 57e33c5b1efbb084ae133d1248f100740fb9b7be Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:29:25 +0200 Subject: [PATCH 07/11] fix typo --- build/ci-build.yml | 4 ++-- build/psgallery-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index e115f542..b69d3886 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -143,9 +143,9 @@ stages: - stage: ReleaseToMyget displayName: 'Release to MyGet' dependsOn: - - ${{ each each UnitTest in parameters.UnitTests }}: + - ${{ each UnitTest in parameters.UnitTests }}: - UnitTests_${{replace(UnitTest.name, '.', '_')}} - - ${{ each each IntegrationTest in parameters.IntegrationTests }}: + - ${{ each IntegrationTest in parameters.IntegrationTests }}: - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} condition: succeeded() jobs: diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index cb4009d9..ffbec181 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -136,9 +136,9 @@ stages: - stage: Release displayName: 'Release to PowerShell Gallery' dependsOn: - - ${{ each each UnitTest in parameters.UnitTests }}: + - ${{ each UnitTest in parameters.UnitTests }}: - UnitTests_${{replace(UnitTest.name, '.', '_')}} - - ${{ each each IntegrationTest in parameters.IntegrationTests }}: + - ${{ each IntegrationTest in parameters.IntegrationTests }}: - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} condition: succeeded() jobs: From 5ef630f2e84a10492cd71fd103dc920044622224 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 11:53:39 +0200 Subject: [PATCH 08/11] fix activedirectory unit tests --- .../Arcus.Scripting.ActiveDirectory.tests.ps1 | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 index 6b228a42..bec0b4c9 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ActiveDirectory.tests.ps1 @@ -109,6 +109,8 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Mock Write-Host {} + Mock Write-Warning {} + Mock Get-AzADApplication { $Filter | Should -Be "AppId eq '$ClientId'" return [pscustomobject] @{ @@ -138,7 +140,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-MockCalled Get-AzADServicePrincipal -Times 1 Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Found role '$RoleName' on Active Directory Application '$AppName'" } Assert-MockCalled Get-MgServicePrincipalAppRoleAssignedTo -Times 1 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "No role assignments found" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "No role assignments found in Active Directory Application '$AppName'" } } It "Providing a ClientId that has roles and also assignments should succeed" { # Arrange @@ -305,7 +307,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { $AppName = 'SomeApp' $AssignRoleToAppName = 'SomeAppToAssignRoleTo' - Mock Write-Host {} + Mock Write-Warning {} Mock Get-AzADApplication { if ($Filter -eq "AppId eq '$ClientId'") { @@ -346,9 +348,9 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-VerifiableMock Assert-MockCalled Get-AzADApplication -Times 2 Assert-MockCalled Get-AzADServicePrincipal -Times 2 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Active Directory Application '$AppName' already contains the role '$RoleName'" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "Active Directory Application '$AppName' already contains the role '$RoleName'" } Assert-MockCalled Get-MgServicePrincipalAppRoleAssignedTo -Times 1 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Active Directory Application '$AssignRoleToAppName' already contains a role assignment for the role '$RoleName'" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "Active Directory Application '$AssignRoleToAppName' already contains a role assignment for the role '$RoleName'" } } It "Providing a role that already exists and does not have a role assignment should succeed" { # Arrange @@ -361,6 +363,8 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Mock Write-Host {} + Mock Write-Warning {} + Mock Get-AzADApplication { if ($Filter -eq "AppId eq '$ClientId'") { return [pscustomobject] @{ @@ -413,7 +417,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-VerifiableMock Assert-MockCalled Get-AzADApplication -Times 2 Assert-MockCalled Get-AzADServicePrincipal -Times 2 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Active Directory Application '$AppName' already contains the role '$RoleName'" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "Active Directory Application '$AppName' already contains the role '$RoleName'" } Assert-MockCalled Get-MgServicePrincipalAppRoleAssignedTo -Times 1 Assert-MockCalled Get-MgServicePrincipal -Times 1 Assert-MockCalled New-MgServicePrincipalAppRoleAssignment -Times 1 @@ -485,7 +489,6 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-VerifiableMock Assert-MockCalled Get-AzADApplication -Times 2 Assert-MockCalled Get-AzADServicePrincipal -Times 2 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Active Directory Application '$AppName' does not contain the role '$RoleName', adding the role" } Assert-MockCalled Update-AzADApplication -Times 1 Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Added Role '$RoleName' to Active Directory Application '$AppName'" } Assert-MockCalled Get-MgServicePrincipalAppRoleAssignedTo -Times 1 @@ -605,7 +608,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { $RemoveRoleFromClientId = '9876' $AppName = 'SomeApp' - Mock Write-Host {} + Mock Write-Warning {} Mock Get-AzADApplication { if ($Filter -eq "AppId eq '$ClientId'") { @@ -630,7 +633,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-VerifiableMock Assert-MockCalled Get-AzADApplication -Times 2 Assert-MockCalled Get-AzADServicePrincipal -Times 2 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Active Directory Application '$AppName' does not contain the role '$RoleName', skipping removal" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "Active Directory Application '$AppName' does not contain the role '$RoleName', skipping removal" } } It "Providing a role that has no role assignment on the Active Directory Application it should be removed from should succeed" { # Arrange @@ -641,7 +644,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { $AppName = 'SomeApp' $RemoveRoleFromAppName = 'SomeAppToRemoveRoleFrom' - Mock Write-Host {} + Mock Write-Warning {} Mock Get-AzADApplication { if ($Filter -eq "AppId eq '$ClientId'") { @@ -680,7 +683,7 @@ InModuleScope Arcus.Scripting.ActiveDirectory { Assert-MockCalled Get-AzADApplication -Times 2 Assert-MockCalled Get-AzADServicePrincipal -Times 2 Assert-MockCalled Get-MgServicePrincipalAppRoleAssignedTo -Times 1 - Assert-MockCalled Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Role '$RoleName' is not assigned to Active Directory Application '$RemoveRoleFromAppName', skipping role assignment removal" } + Assert-MockCalled Write-Warning -Exactly 1 -ParameterFilter { $Message -eq "Role '$RoleName' is not assigned to Active Directory Application '$RemoveRoleFromAppName', skipping role assignment removal" } } It "Providing a role that has a role assignment on the Active Directory Application it should be removed from should succeed" { # Arrange From ce67e268a7573af6bf1d088d3e5198a64925c549 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 12:00:39 +0200 Subject: [PATCH 09/11] try unit tests within one stage but separate jobs --- build/ci-build.yml | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index b69d3886..8780bb64 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -91,26 +91,26 @@ stages: targetPath: '$(Pipeline.Workspace)/build' artifactName: Build - - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{replace(UnitTest.name, '.', '_')}} - displayName: Unit Tests - ${{UnitTest.name}} - dependsOn: Build - condition: succeeded() - jobs: - - job: RunUnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Linux.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Unit' - testName: '$(Project).${{UnitTest.name}}' + - stage: UnitTests + displayName: Unit Tests + dependsOn: Build + condition: succeeded() + jobs: + - ${{ each UnitTest in parameters.UnitTests }}: + - job: RunUnitTests_${{replace(UnitTest.name, '.', '_')}} + displayName: 'Run unit tests - ${{IntegrationTest.name}}' + pool: + vmImage: '$(Vm.Linux.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Unit' + testName: '$(Project).${{UnitTest.name}}' - ${{ each IntegrationTest in parameters.IntegrationTests }}: - stage: IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} @@ -143,8 +143,7 @@ stages: - stage: ReleaseToMyget displayName: 'Release to MyGet' dependsOn: - - ${{ each UnitTest in parameters.UnitTests }}: - - UnitTests_${{replace(UnitTest.name, '.', '_')}} + - UnitTests - ${{ each IntegrationTest in parameters.IntegrationTests }}: - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} condition: succeeded() From 0234aabe8534b849aed324c599174ba8c986ea7a Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 12:01:20 +0200 Subject: [PATCH 10/11] fix name --- build/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 8780bb64..b6c6c4b4 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -98,7 +98,7 @@ stages: jobs: - ${{ each UnitTest in parameters.UnitTests }}: - job: RunUnitTests_${{replace(UnitTest.name, '.', '_')}} - displayName: 'Run unit tests - ${{IntegrationTest.name}}' + displayName: 'Run unit tests - ${{UnitTest.name}}' pool: vmImage: '$(Vm.Linux.Image)' steps: From 52670684679ee44e04f897491012dcd9ef21b817 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 24 Aug 2023 12:04:48 +0200 Subject: [PATCH 11/11] use multiple jobs instead of stages --- build/ci-build.yml | 57 ++++++++++---------- build/psgallery-release.yml | 100 ++++++++++++++++++------------------ 2 files changed, 77 insertions(+), 80 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index b6c6c4b4..83e91248 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -112,40 +112,39 @@ stages: projectName: '$(Project).Tests.Unit' testName: '$(Project).${{UnitTest.name}}' - - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} - displayName: Integration Tests - ${{IntegrationTest.name}} - dependsOn: Build - condition: succeeded() - 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: '$(imageName)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Integration' - testName: '$(Project).${{IntegrationTest.name}}' + - stage: IntegrationTests + displayName: Integration Tests + dependsOn: Build + condition: succeeded() + jobs: + - ${{ each IntegrationTest in parameters.IntegrationTests }}: + - job: RunIntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} + displayName: 'Run integration tests - ${{IntegrationTest.name}}' + strategy: + maxParallel: 1 + matrix: + linux: + imageName: ${{ variables['Vm.Linux.Image']}} + windows: + imageName: ${{ variables['Vm.Windows.Image']}} + pool: + vmImage: '$(imageName)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Integration' + testName: '$(Project).${{IntegrationTest.name}}' - stage: ReleaseToMyget displayName: 'Release to MyGet' dependsOn: - UnitTests - - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} + - IntegrationTests condition: succeeded() jobs: - job: PushToMyGet diff --git a/build/psgallery-release.yml b/build/psgallery-release.yml index ffbec181..7e441d69 100644 --- a/build/psgallery-release.yml +++ b/build/psgallery-release.yml @@ -84,62 +84,60 @@ stages: targetPath: '$(Pipeline.Workspace)/build' artifactName: Build - - ${{ each UnitTest in parameters.UnitTests }}: - - stage: UnitTests_${{replace(UnitTest.name, '.', '_')}} - displayName: Unit Tests - ${{UnitTest.name}} - dependsOn: Build - condition: succeeded() - jobs: - - job: RunUnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Linux.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Unit' - testName: '$(Project).${{UnitTest.name}}' + - stage: UnitTests + displayName: Unit Tests + dependsOn: Build + condition: succeeded() + jobs: + - ${{ each UnitTest in parameters.UnitTests }}: + - job: RunUnitTests_${{replace(UnitTest.name, '.', '_')}} + displayName: 'Run unit tests - ${{UnitTest.name}}' + pool: + vmImage: '$(Vm.Linux.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Unit' + testName: '$(Project).${{UnitTest.name}}' - - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - stage: IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} - displayName: Integration Tests - ${{IntegrationTest.name}} - dependsOn: Build - condition: succeeded() - 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: '$(imageName)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: 'templates/run-pester-tests.yml' - parameters: - projectName: '$(Project).Tests.Integration' - testName: '$(Project).${{IntegrationTest.name}}' + - stage: IntegrationTests + displayName: Integration Tests + dependsOn: Build + condition: succeeded() + jobs: + - ${{ each IntegrationTest in parameters.IntegrationTests }}: + - job: RunIntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} + displayName: 'Run integration tests - ${{IntegrationTest.name}}' + strategy: + maxParallel: 1 + matrix: + linux: + imageName: ${{ variables['Vm.Linux.Image']}} + windows: + imageName: ${{ variables['Vm.Windows.Image']}} + pool: + vmImage: '$(imageName)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - template: 'templates/run-pester-tests.yml' + parameters: + projectName: '$(Project).Tests.Integration' + testName: '$(Project).${{IntegrationTest.name}}' - stage: Release displayName: 'Release to PowerShell Gallery' dependsOn: - - ${{ each UnitTest in parameters.UnitTests }}: - - UnitTests_${{replace(UnitTest.name, '.', '_')}} - - ${{ each IntegrationTest in parameters.IntegrationTests }}: - - IntegrationTests_${{replace(IntegrationTest.name, '.', '_')}} + - UnitTests + - IntegrationTests condition: succeeded() jobs: - job: PushToNuGet