Skip to content

Add integration test stage for DSCv3 #2102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"analyzersettings",
"sqlcmd",
"PBIRS",
"SSRS"
"SSRS",
"PSDSC"
],
"cSpell.ignorePaths": [
".git"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added new instructions for GitHub Copilot that might assist when developing
command and private functions in the module. More instructions should be
added as needed to help generated code and tests.
- Add integration test in DSCv3.

### Changed

Expand Down
93 changes: 93 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,99 @@ stages:
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Integration RS ($(TEST_CONFIGURATION) / $(JOB_VMIMAGE))'

- stage: Integration_Test_DSCv3_Resources_PowerBIReportServer
displayName: 'Integration Test DSCv3 Resources - Power BI Report Server'
#dependsOn: Quality_Test_and_Unit_Test
dependsOn: Build
jobs:
- job: Test_Integration
displayName: 'Integration'
strategy:
matrix:
PowerBI_WIN2019:
JOB_VMIMAGE: 'windows-2019'
TEST_CONFIGURATION: 'Integration_PowerBI'
PowerBI_WIN2022:
JOB_VMIMAGE: 'windows-2022'
TEST_CONFIGURATION: 'Integration_PowerBI'
PowerBI_WIN2025:
JOB_VMIMAGE: 'windows-2025'
TEST_CONFIGURATION: 'Integration_PowerBI'
pool:
vmImage: $(JOB_VMIMAGE)
timeoutInMinutes: 0
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download Build Artifact'
inputs:
buildType: 'current'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)'
- task: PowerShell@2
name: configureWinRM
displayName: 'Configure WinRM'
inputs:
targetType: 'inline'
script: 'winrm quickconfig -quiet'
pwsh: false
- powershell: |
Import-Module -Name ./tests/TestHelpers/CommonTestHelper.psm1
Remove-PowerShellModuleFromCI -Name @('SqlServer', 'SQLPS')
Remove-Module -Name CommonTestHelper
name: cleanCIWorker
displayName: 'Clean CI worker'
- pwsh: |
Install-PSResource -Name 'PSDSC' -Repository 'PSGallery' -TrustRepository -Quiet -Confirm:$false
#Install-DscExe -Force -Verbose
Install-DscExe -Version 3.1.0-preview.5 -Force -Verbose
name: installDSCv3
displayName: 'Install DSCv3'
- pwsh: |
# Install-DscExe installs in the path $env:LOCALAPPDATA\dsc
$env:PATH += '{0}{1}' -f [System.IO.Path]::PathSeparator, (Join-Path -Path $env:LOCALAPPDATA -ChildPath 'dsc')
# Make the built module available to the current session.
./build.ps1 -Tasks noop
Get-Module -Name SqlServerDsc -ListAvailable
# Output DSCv3 version
dsc --version
# Get the list of available resources.
'Native resources:'
dsc resource list
'Resources using adapter Microsoft.Windows/WindowsPowerShell:'
dsc resource list --adapter Microsoft.Windows/WindowsPowerShell

Get-ChildItem -Path (Join-Path -Path $env:LOCALAPPDATA -ChildPath 'dsc') -Recurse -Filter '*.json'
$cacheFile = Join-Path -Path $env:LOCALAPPDATA -ChildPath 'dsc/WindowsPSAdapterCache.json'
$getConfig = Get-Content -Path $cacheFile -Raw | ConvertFrom-Json
Write-Verbose -Message "WindowsPSAdapterCache.json content:`n $($getConfig | Out-String)" -Verbose
Write-Verbose -Message "WindowsPSAdapterCache.json content:`n $($getConfig | ConvertTo-Json -Depth 10)" -Verbose
name: getDSCv3AvailableResources
displayName: 'Get DSCv3 Available Resources'
- pwsh: |
# Install-DscExe installed in the path $env:LOCALAPPDATA\dsc
$env:PATH += '{0}{1}' -f [System.IO.Path]::PathSeparator, (Join-Path -Path $env:LOCALAPPDATA -ChildPath 'dsc')
./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterTag $(TEST_CONFIGURATION) -PesterPath @(
# Run the integration tests in a specific group order.
# Prerequisites
# TODO: Move the prerequisites tests to generic folder than Commands
'tests/Integration/Commands/Prerequisites.Integration.Tests.ps1'
# Group 1
#'tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1'
# Group 2
'tests/Integration/Resources/DSCv3_SqlRSSetup.Integration.Tests.ps1'
# Group 3
#'tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1'
)
name: test
displayName: 'Run Reporting Services Integration Test'
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Integration RS ($(TEST_CONFIGURATION) / $(JOB_VMIMAGE))'

- stage: Integration_Test_Resources_ReportingServices_dbatools
displayName: 'Integration Test Resources - Reporting Services (dbatools)'
dependsOn: Integration_Test_Resources_SqlServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Describe 'Prerequisites' {
It 'Should have the minimum required version of Microsoft.PowerShell.PSResourceGet' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_PowerBI', 'Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
$module = Get-Module -Name 'Microsoft.PowerShell.PSResourceGet' -ListAvailable

$module | Should -HaveCount 1
$module.Version -ge '1.0.4.1' | Should -BeTrue
$module.Count | Should -BeGreaterOrEqual 1
#$module.Version -ge '1.0.4.1' | Should -BeTrue
}

It 'Should have a resource repository PSGallery with correct URI' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_PowerBI', 'Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
try
{
if (-not (Get-Module -Name 'DscResource.Test'))
{
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# If the dependencies has not been resolved, this will throw an error.
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
}
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
}

<#
Need to define that variables here to be used in the Pester Discover to
build the ForEach-blocks.
#>
$script:dscResourceFriendlyName = 'SqlRSSetup'
}

BeforeAll {
# Need to define the variables here which will be used in Pester Run.
$script:dscModuleName = 'SqlServerDsc'
$script:dscResourceFriendlyName = 'SqlRSSetup'
}

<#
Run only for standalone versions of Microsoft SQL Server Reporting Services
and Power BI Report Server. Older versions of Reporting Services (eg. 2016)
are integration tested in separate tests (part of resource SqlSetup).
#>
Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_PowerBI') {
Context 'When getting the current state of the resource' {
It 'Should return the expected current state' {
# Media file has already been saved to (Get-TemporaryFolder)\PowerBIReportServer.exe
$desiredParameters = @{
InstanceName = 'PBIRS'
AcceptLicensingTerms = $true
Action = 'Install'
MediaPath = Join-Path -Path (Get-TemporaryFolder) -ChildPath 'PowerBIReportServer.exe'
InstallFolder = Join-Path -Path $env:ProgramFiles -ChildPath 'Microsoft Power BI Report Server'
Edition = 'Developer'
SuppressRestart = $true
LogPath = Join-Path -Path (Get-TemporaryFolder) -ChildPath 'PBIRS.log'
VersionUpgrade = $true
}

dsc --trace-level trace resource get --resource SqlServerDsc/SqlRSSetup --output-format pretty-json --input ($desiredParameters | ConvertTo-Json -Compress)

if ($LASTEXITCODE -ne 0)
{
throw 'Failed to get the current state of the resource.'
}
}
}
}
Loading