From 9c8e24a0959b8c80b802b483c53c26eaa7cb7a67 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 18:36:21 +0000 Subject: [PATCH 01/13] Added '-ErrorAction Stop' to 'Test-DscConfiguration' calls in 'AzDevOpsProject' integration tests. --- .../AzDevOpsProject.Integration.Tests.ps1 | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 index 230f5cd95..da82c5864 100644 --- a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 +++ b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 @@ -96,7 +96,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -156,7 +156,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -201,9 +201,9 @@ try } | Should -Not -Throw } - It 'Should return $false or $null when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeIn @('False',$null) - } + It 'Should return $false or $null when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -BeIn @('False',$null) + } } @@ -258,7 +258,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -315,7 +315,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -375,7 +375,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -477,7 +477,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -538,7 +538,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -599,7 +599,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -659,7 +659,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } @@ -716,7 +716,7 @@ try It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'True' } } From 5582c1b7b0040c72124146c987a3e65abc2d9de2 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 18:38:18 +0000 Subject: [PATCH 02/13] Added try/catch within GetDesiredStateParameters() method in 'AzDevOpsDscResourceBase' class. Also used 'New-InvalidOperationException' when exceptions thrown. --- .../Classes/003.AzDevOpsDscResourceBase.ps1 | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/source/Classes/003.AzDevOpsDscResourceBase.ps1 b/source/Classes/003.AzDevOpsDscResourceBase.ps1 index fa1505986..486efa960 100644 --- a/source/Classes/003.AzDevOpsDscResourceBase.ps1 +++ b/source/Classes/003.AzDevOpsDscResourceBase.ps1 @@ -79,7 +79,9 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase $thisType = $this.GetType() if ($thisType -eq [AzDevOpsDscResourceBase]) { - throw "Method 'GetCurrentState()' in '$($thisType.Name)' must be overidden and called by an inheriting class." + # If all retry attempts have failed, throw an exception + $errorMessage = "Method 'GetCurrentState()' in '$($thisType.Name)' must be overidden and called by an inheriting class." + New-InvalidOperationException -Message $errorMessage } return $null } @@ -143,7 +145,9 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase if ($($currentProperties[$_].ToString()) -ne $($desiredProperties[$_].ToString())) { - throw "The '$($this.GetType().Name)', DSC Resource does not support changes for/to the '$_' property." + # If all retry attempts have failed, throw an exception + $errorMessage = "The '$($this.GetType().Name)', DSC Resource does not support changes for/to the '$_' property." + New-InvalidOperationException -Message $errorMessage break } } @@ -188,7 +192,9 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase break } default { - throw "Could not obtain a valid 'Ensure' value within 'AzDevOpsProject' Test() function. Value was '$($desiredProperties.Ensure)'." + $errorMessage = "Could not obtain a valid 'Ensure' value within 'AzDevOpsProject' Test() function. Value was '$($desiredProperties.Ensure)'." + New-InvalidOperationException -Message $errorMessage + return [RequiredAction]::Error } } @@ -258,7 +264,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase } else { - throw "A required action of '$RequiredAction' has not been catered for in GetDesiredStateParameters() method." + $errorMessage = "A required action of '$RequiredAction' has not been catered for in GetDesiredStateParameters() method." + New-InvalidOperationException -Message $errorMessage } @@ -273,7 +280,15 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase [System.Boolean] Test() { - return $this.TestDesiredState() + # TestDesiredState() will throw an exception in certain expected circumstances. Return $false if this occurs. + try + { + return $this.TestDesiredState() + } + catch + { + return $false + } } From 756a9875a539407fcb0049cbe21fce9c616b2f41 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 18:41:55 +0000 Subject: [PATCH 03/13] Updated 'DscResourceBase' to use 'New-InvalidOperationException' method when throwing exceptions. --- source/Classes/001.DscResourceBase.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/Classes/001.DscResourceBase.ps1 b/source/Classes/001.DscResourceBase.ps1 index d0a0c029e..4dd52ddf4 100644 --- a/source/Classes/001.DscResourceBase.ps1 +++ b/source/Classes/001.DscResourceBase.ps1 @@ -6,7 +6,8 @@ class DscResourceBase if ([String]::IsNullOrWhiteSpace($dscResourceKeyPropertyName)) { - throw "Cannot obtain a 'DscResourceKey' value for the '$($this.GetType().Name)' instance." + $errorMessage = "Cannot obtain a 'DscResourceKey' value for the '$($this.GetType().Name)' instance." + New-InvalidOperationException -Message $errorMessage } return $this."$dscResourceKeyPropertyName" @@ -37,12 +38,14 @@ class DscResourceBase if ($null -eq $dscResourceKeyPropertyNames -or $dscResourceKeyPropertyNames.Count -eq 0) { - throw "Could not obtain a 'DscResourceDscKey' property for type '$($this.GetType().Name)'." + $errorMessage = "Could not obtain a 'DscResourceDscKey' property for type '$($this.GetType().Name)'." + New-InvalidOperationException -Message $errorMessage } elseif ($dscResourceKeyPropertyNames.Count -gt 1) { - throw "Obtained more than 1 property for type '$($this.GetType().Name)' that was marked as a 'Key'. There must only be 1 property on the class set as the 'Key' for DSC." + $errorMessage = "Obtained more than 1 property for type '$($this.GetType().Name)' that was marked as a 'Key'. There must only be 1 property on the class set as the 'Key' for DSC." + New-InvalidOperationException -Message $errorMessage } return $dscResourceKeyPropertyNames[0] From 71df31b44e00c33876d4b517922f629e70249b5c Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:17:15 +0000 Subject: [PATCH 04/13] Added integration tests back into 'azure-pipelines.yml' --- azure-pipelines.yml | 49 +++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ddd2d4ca2..f90eac531 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -191,34 +191,31 @@ stages: script: 'winrm quickconfig -quiet' pwsh: false - # TODO: Current disabled due to integration tests throws the exception: - # "Cannot validate argument on parameter 'Pat'. The " Test-AzDevOpsPat -Pat $_ -IsValid " validation script for the argument with value "$(AzureDevOps.Integration.Pat)" did not return a result of True. Determine why the validation script failed, and then try the command again." - - # - powershell: | - # ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( - # 'tests/Integration/' - # ) - # name: test - # displayName: 'Run Integration Tests' - # env: - # azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) - # azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) + - powershell: | + ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( + 'tests/Integration/' + ) + name: test + displayName: 'Run Integration Tests' + env: + azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) + azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) - # - task: PublishTestResults@2 - # displayName: 'Publish Test Results' - # condition: succeededOrFailed() - # inputs: - # testResultsFormat: 'NUnit' - # testResultsFiles: 'output/testResults/NUnit*.xml' - # testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' - # - task: PublishCodeCoverageResults@1 - # displayName: 'Publish Code Coverage' - # condition: succeededOrFailed() - # inputs: - # codeCoverageTool: 'JaCoCo' - # summaryFileLocation: 'output/testResults/CodeCov*.xml' - # pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Code Coverage' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'JaCoCo' + summaryFileLocation: 'output/testResults/CodeCov*.xml' + pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - job: test_unit_windows_ps condition: succeededOrFailed() From e1653a134bc6add817bfa405f14805473183e94a Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:25:41 +0000 Subject: [PATCH 05/13] Updated 'CONTRIBUTING.md' to add additional environment variable to PowerShell. --- CONTRIBUTING.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4e371f08..cafa70440 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,13 +84,15 @@ development), the following actions need to be performed: initiated. * You need to set the following environment variables so the build will determine - it needs to execute the Integration tests, and it has the Personal Access Token - (PAT) and API URI + it needs to execute the Integration tests, and it can use the [Personal Access Token + (PAT)](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page) + and API URI ```Powershell $env:CI = $true - $env:AZUREDEVOPSINTEGRATIONAPIURI = 'YourApiUriHere' - $env:AZUREDEVOPSINTEGRATIONPAT = 'YourPatHere' + $env:CONFIGURATION = 'Integration' + $env:AZUREDEVOPSINTEGRATIONAPIURI = 'YourApiUriHere' # IMPORTANT: Ensure this is a destructable organization/collection + $env:AZUREDEVOPSINTEGRATIONPAT = 'YourPatHere' # This PAT must have access to update resources ``` >**Important**: It is not recommended to store any Personal Access Token (PAT) From 2045e549cae0c20daae9ea23265291568973c42c Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:33:23 +0000 Subject: [PATCH 06/13] Updated 'CHANGELOG.md' --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d40af3d8..a32e8560a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - AzureDevOpsDsc - Updated pipeline files to support change of default branch to main. - - Added GitHub issue templates and pull request template ([issue #1](https://github.com/dsccommunity/AzureDevOpsDsc/issues/1)) + - Added GitHub issue templates and pull request template + ([issue #1](https://github.com/dsccommunity/AzureDevOpsDsc/issues/1)) - Added the `AzDevOpsProject`, DSC Resource + - Fixed non-terminating, integration tests ([issue #18](https://github.com/dsccommunity/AzureDevOpsDsc/issues/18)) - AzureDevOpsDsc.Common - Added 'wrapper' functionality around the [Azure DevOps REST API](https://docs.microsoft.com/en-us/rest/api/azure/devops/) From 365ee24894e17bf643a5075e55f7e146ca40fd21 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:38:09 +0000 Subject: [PATCH 07/13] Removed 'test_integration_windows_core' tasks in 'azure-pipelines.yml' --- azure-pipelines.yml | 103 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f90eac531..69f41cabd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -164,6 +164,60 @@ stages: summaryFileLocation: 'output/testResults/CodeCov*.xml' pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + # TODO: Current disabled due to integration tests throws the exception: + # "Cannot validate argument on parameter 'Pat'. The " Test-AzDevOpsPat -Pat $_ -IsValid " validation script for the argument with value "$(AzureDevOps.Integration.Pat)" did not return a result of True. Determine why the validation script failed, and then try the command again." + + # - powershell: | + # ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( + # 'tests/Integration/' + # ) + # name: test + # displayName: 'Run Integration Tests' + # env: + # azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) + # azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) + - powershell: | + ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( + 'tests/Integration/' + ) + name: test + displayName: 'Run Integration Tests' + env: + azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) + azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) + # - task: PublishTestResults@2 + # displayName: 'Publish Test Results' + # condition: succeededOrFailed() + # inputs: + # testResultsFormat: 'NUnit' + # testResultsFiles: 'output/testResults/NUnit*.xml' + # testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' + + # - task: PublishCodeCoverageResults@1 + # displayName: 'Publish Code Coverage' + # condition: succeededOrFailed() + # inputs: + # codeCoverageTool: 'JaCoCo' + # summaryFileLocation: 'output/testResults/CodeCov*.xml' + # pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Code Coverage' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'JaCoCo' + summaryFileLocation: 'output/testResults/CodeCov*.xml' + pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + + - job: test_unit_windows_ps + condition: succeededOrFailed() + - job: test_integration_windows_core displayName: 'Windows (PowerShell Core) - Integration Tests' timeoutInMinutes: 0 @@ -191,31 +245,34 @@ stages: script: 'winrm quickconfig -quiet' pwsh: false - - powershell: | - ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( - 'tests/Integration/' - ) - name: test - displayName: 'Run Integration Tests' - env: - azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) - azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) + # TODO: Current disabled due to integration tests throws the exception: + # "Cannot validate argument on parameter 'Pat'. The " Test-AzDevOpsPat -Pat $_ -IsValid " validation script for the argument with value "$(AzureDevOps.Integration.Pat)" did not return a result of True. Determine why the validation script failed, and then try the command again." - - task: PublishTestResults@2 - displayName: 'Publish Test Results' - condition: succeededOrFailed() - inputs: - testResultsFormat: 'NUnit' - testResultsFiles: 'output/testResults/NUnit*.xml' - testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' + # - powershell: | + # ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( + # 'tests/Integration/' + # ) + # name: test + # displayName: 'Run Integration Tests' + # env: + # azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) + # azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) - - task: PublishCodeCoverageResults@1 - displayName: 'Publish Code Coverage' - condition: succeededOrFailed() - inputs: - codeCoverageTool: 'JaCoCo' - summaryFileLocation: 'output/testResults/CodeCov*.xml' - pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + # - task: PublishTestResults@2 + # displayName: 'Publish Test Results' + # condition: succeededOrFailed() + # inputs: + # testResultsFormat: 'NUnit' + # testResultsFiles: 'output/testResults/NUnit*.xml' + # testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' + + # - task: PublishCodeCoverageResults@1 + # displayName: 'Publish Code Coverage' + # condition: succeededOrFailed() + # inputs: + # codeCoverageTool: 'JaCoCo' + # summaryFileLocation: 'output/testResults/CodeCov*.xml' + # pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - job: test_unit_windows_ps condition: succeededOrFailed() From a71e36fc50acdd95dbb0d0a2568402c98a9ce5cd Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:39:54 +0000 Subject: [PATCH 08/13] Removed 'test_integration_windows_core', build job in 'azure-pipelines.yml' --- azure-pipelines.yml | 56 --------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 69f41cabd..4942b34d7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -218,62 +218,6 @@ stages: - job: test_unit_windows_ps condition: succeededOrFailed() - - job: test_integration_windows_core - displayName: 'Windows (PowerShell Core) - Integration Tests' - timeoutInMinutes: 0 - variables: - # This sets environment variable $env:CI. - CI: true - # This sets environment variable $env:CONFIGURATION. - configuration: Integration - pool: - vmImage: 'windows-2019' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifact' - inputs: - buildType: 'current' - downloadType: 'single' - artifactName: 'output' - downloadPath: '$(Build.SourcesDirectory)' - - - task: PowerShell@2 - name: configureWinRM - displayName: 'Configure WinRM' - inputs: - targetType: 'inline' - script: 'winrm quickconfig -quiet' - pwsh: false - - # TODO: Current disabled due to integration tests throws the exception: - # "Cannot validate argument on parameter 'Pat'. The " Test-AzDevOpsPat -Pat $_ -IsValid " validation script for the argument with value "$(AzureDevOps.Integration.Pat)" did not return a result of True. Determine why the validation script failed, and then try the command again." - - # - powershell: | - # ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( - # 'tests/Integration/' - # ) - # name: test - # displayName: 'Run Integration Tests' - # env: - # azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) - # azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) - - # - task: PublishTestResults@2 - # displayName: 'Publish Test Results' - # condition: succeededOrFailed() - # inputs: - # testResultsFormat: 'NUnit' - # testResultsFiles: 'output/testResults/NUnit*.xml' - # testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' - - # - task: PublishCodeCoverageResults@1 - # displayName: 'Publish Code Coverage' - # condition: succeededOrFailed() - # inputs: - # codeCoverageTool: 'JaCoCo' - # summaryFileLocation: 'output/testResults/CodeCov*.xml' - # pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - - job: test_unit_windows_ps condition: succeededOrFailed() displayName: 'Windows (Windows PowerShell) - Unit Tests' From 6c04aa1d360be5d07bed3bc7a8c9ce6d1cae1653 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Mon, 25 Jan 2021 19:41:46 +0000 Subject: [PATCH 09/13] Updated 'azure-pipelines.yml' to reflect 'main' branch --- azure-pipelines.yml | 56 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4942b34d7..ddd2d4ca2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -164,7 +164,34 @@ stages: summaryFileLocation: 'output/testResults/CodeCov*.xml' pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - # TODO: Current disabled due to integration tests throws the exception: + - job: test_integration_windows_core + displayName: 'Windows (PowerShell Core) - Integration Tests' + timeoutInMinutes: 0 + variables: + # This sets environment variable $env:CI. + CI: true + # This sets environment variable $env:CONFIGURATION. + configuration: Integration + pool: + vmImage: 'windows-2019' + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: configureWinRM + displayName: 'Configure WinRM' + inputs: + targetType: 'inline' + script: 'winrm quickconfig -quiet' + pwsh: false + + # TODO: Current disabled due to integration tests throws the exception: # "Cannot validate argument on parameter 'Pat'. The " Test-AzDevOpsPat -Pat $_ -IsValid " validation script for the argument with value "$(AzureDevOps.Integration.Pat)" did not return a result of True. Determine why the validation script failed, and then try the command again." # - powershell: | @@ -176,15 +203,7 @@ stages: # env: # azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) # azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) - - powershell: | - ./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterScript @( - 'tests/Integration/' - ) - name: test - displayName: 'Run Integration Tests' - env: - azureDevOpsIntegrationApiUri: $(AzureDevOps.Integration.ApiUri) - azureDevOpsIntegrationPat: $(AzureDevOps.Integration.Pat) + # - task: PublishTestResults@2 # displayName: 'Publish Test Results' # condition: succeededOrFailed() @@ -192,13 +211,6 @@ stages: # testResultsFormat: 'NUnit' # testResultsFiles: 'output/testResults/NUnit*.xml' # testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' - - task: PublishTestResults@2 - displayName: 'Publish Test Results' - condition: succeededOrFailed() - inputs: - testResultsFormat: 'NUnit' - testResultsFiles: 'output/testResults/NUnit*.xml' - testRunTitle: 'Windows Server Core (PowerShell Core) - Integration' # - task: PublishCodeCoverageResults@1 # displayName: 'Publish Code Coverage' @@ -207,16 +219,6 @@ stages: # codeCoverageTool: 'JaCoCo' # summaryFileLocation: 'output/testResults/CodeCov*.xml' # pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - - task: PublishCodeCoverageResults@1 - displayName: 'Publish Code Coverage' - condition: succeededOrFailed() - inputs: - codeCoverageTool: 'JaCoCo' - summaryFileLocation: 'output/testResults/CodeCov*.xml' - pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' - - - job: test_unit_windows_ps - condition: succeededOrFailed() - job: test_unit_windows_ps condition: succeededOrFailed() From 90bf28b0208bcf6e4f13502515e808e4b62bdae4 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Tue, 26 Jan 2021 04:39:14 +0000 Subject: [PATCH 10/13] Remove post-exception, non-executed code and some inaccurate comments from `AzDevOpsDscResourceBase` class. --- source/Classes/003.AzDevOpsDscResourceBase.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Classes/003.AzDevOpsDscResourceBase.ps1 b/source/Classes/003.AzDevOpsDscResourceBase.ps1 index 486efa960..27771dfac 100644 --- a/source/Classes/003.AzDevOpsDscResourceBase.ps1 +++ b/source/Classes/003.AzDevOpsDscResourceBase.ps1 @@ -79,7 +79,6 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase $thisType = $this.GetType() if ($thisType -eq [AzDevOpsDscResourceBase]) { - # If all retry attempts have failed, throw an exception $errorMessage = "Method 'GetCurrentState()' in '$($thisType.Name)' must be overidden and called by an inheriting class." New-InvalidOperationException -Message $errorMessage } @@ -145,10 +144,8 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase if ($($currentProperties[$_].ToString()) -ne $($desiredProperties[$_].ToString())) { - # If all retry attempts have failed, throw an exception $errorMessage = "The '$($this.GetType().Name)', DSC Resource does not support changes for/to the '$_' property." New-InvalidOperationException -Message $errorMessage - break } } } @@ -194,8 +191,6 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase default { $errorMessage = "Could not obtain a valid 'Ensure' value within 'AzDevOpsProject' Test() function. Value was '$($desiredProperties.Ensure)'." New-InvalidOperationException -Message $errorMessage - - return [RequiredAction]::Error } } From 7de58e17899cf8961eff42a22967221f97258a24 Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Tue, 26 Jan 2021 04:41:29 +0000 Subject: [PATCH 11/13] Added additional '-ErrorAction Stop' to 'Test-DscConfiguration' call in 'AzDevOpsProject', integration tests. --- .../DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 index da82c5864..dc4444d0a 100644 --- a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 +++ b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 @@ -421,7 +421,7 @@ try } It 'Should return $false or $null when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeIn @('False',$null) + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -BeIn @('False',$null) } } From 21ac673091a3a0e624d01317805b6117abeecbdf Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Tue, 26 Jan 2021 04:47:36 +0000 Subject: [PATCH 12/13] Updated 2 intergration tests to ensure 'Test-DscConfiguration' returns 'False' (and not 'False' or $null) --- .../DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 index dc4444d0a..1bb93179d 100644 --- a/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 +++ b/tests/Integration/DSCClassResources/AzDevOpsProject.Integration.Tests.ps1 @@ -202,7 +202,7 @@ try } It 'Should return $false or $null when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose -ErrorAction Stop | Should -BeIn @('False',$null) + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'False' } } @@ -421,7 +421,7 @@ try } It 'Should return $false or $null when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose -ErrorAction Stop | Should -BeIn @('False',$null) + Test-DscConfiguration -Verbose -ErrorAction Stop | Should -Be 'False' } } From 88b48f6f3cb6d307bfeb110a7f1536a686411cbc Mon Sep 17 00:00:00 2001 From: Paul Wilcox Date: Tue, 26 Jan 2021 05:25:44 +0000 Subject: [PATCH 13/13] Replaced 'AzDevOpsProject' value within 'AzDevOpsDscResourceBase' base class to, instead, make use of function to obtain resource name from the inheriting, class/resource. --- source/Classes/003.AzDevOpsDscResourceBase.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Classes/003.AzDevOpsDscResourceBase.ps1 b/source/Classes/003.AzDevOpsDscResourceBase.ps1 index 27771dfac..aa7bf4593 100644 --- a/source/Classes/003.AzDevOpsDscResourceBase.ps1 +++ b/source/Classes/003.AzDevOpsDscResourceBase.ps1 @@ -189,7 +189,7 @@ class AzDevOpsDscResourceBase : AzDevOpsApiDscResourceBase break } default { - $errorMessage = "Could not obtain a valid 'Ensure' value within 'AzDevOpsProject' Test() function. Value was '$($desiredProperties.Ensure)'." + $errorMessage = "Could not obtain a valid 'Ensure' value within '$($this.GetResourceName())' Test() function. Value was '$($desiredProperties.Ensure)'." New-InvalidOperationException -Message $errorMessage } }