Skip to content

Commit

Permalink
SqlRS: Add new integration test jobs (#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Mar 25, 2023
1 parent 5efa82d commit 67aa742
Show file tree
Hide file tree
Showing 10 changed files with 936 additions and 260 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SqlServerDsc
- New GitHub Actions workflow that run PSScriptAnalyzer for PRs so any
issues are shown directly in the PR's changed files ([issue #1860](https://github.com/dsccommunity/SqlServerDsc/issues/1860)).
- Added a separate integration test jobs for SQL Server Reporting Services
to be able to test configuring SQL Server Reportings Services using
other values that the default values.

### Changed

Expand All @@ -22,9 +25,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed the regular expression `features?` from the GitVersion configuration.
Before, if a fix commit mentioned the word feature but means a SQL Server
feature GitVersion would bump minor instead of patch number.
- When running in Azure Pipelines any existing SqlServer module is removed
before running integration tests, so the tests can update to latest version.
- `Get-SqlDscAudit`
- The parameter `Name` is no longer mandatory. When left out all the current
audits are returned ([issue #1812](https://github.com/dsccommunity/SqlServerDsc/issues/1812)).
- `Import-SqlDscPreferredModule`
- Now correctly preserves paths that is set in the session for the environment
variable `$env:PSModulePath`. If the module _SqlServer_ or _SQLPS_ are not
found the command will populate the `$env:PSModulePath` with the
unique paths from all targets; session, user, and machine. This is done
so that any new path that was added to the machine or user target will
also be set in the session.
- Now imports the preferred module into the global scope so that MOF-based
resources (that is in another module scope) can use the imported module.

### Fixed

Expand All @@ -41,8 +55,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The parameter `SqlSysAdminAccounts` is no longer mandatory to allow
installation where the database engine is not installed.
- `SqlRS`
- Test renamed to `When Reports virtual directory is different` so it is more correct and not a duplicate
- Fixed issue of configuring reporting services ([issue #1868](https://github.com/dsccommunity/SqlServerDsc/issues/1868)).
- Test renamed to `When Reports virtual directory is different` so it
is more correct and not a duplicate.

## [16.1.0] - 2023-02-28

Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ install:
winrm quickconfig -quiet # cSpell: disable-line
Import-Module -Name ./tests/TestHelpers/CommonTestHelper.psm1
Remove-PowerShellModuleFromCI -Name @('SqlServer', 'SQLPS')
Remove-Module -Name CommonTestHelper
# DEBUG: If running on own AppVeyor project, comment the line below that skips if it is not a pull request
build_script:
- pwsh: |
Expand Down
89 changes: 83 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ variables:
sourceFolderName: source
defaultBranch: main

# cSpell: ignore setvariable updatebuildnumber DSCSQLTEST hqrmtest quickconfig
stages:
- stage: Build
jobs:
Expand Down Expand Up @@ -171,11 +172,6 @@ stages:
pool:
vmImage: $(JOB_VMIMAGE)
timeoutInMinutes: 0
variables:
# This sets environment variable $env:CI.
CI: true
# This sets environment variable $env:SqlServerDscCI.
SqlServerDscCI: true
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download Build Artifact'
Expand All @@ -190,6 +186,12 @@ stages:
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: removeSqlServerModule
displayName: 'Remove SqlServer module'
- powershell: |
./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterTag $(TEST_CONFIGURATION) -PesterPath @(
# Run the integration tests in a specific group order.
Expand All @@ -210,7 +212,7 @@ stages:
'tests/Integration/DSC_SqlTraceFlag.Integration.Tests.ps1'
# Group 3
'tests/Integration/DSC_SqlRole.Integration.Tests.ps1'
'tests/Integration/DSC_SqlRS.Integration.Tests.ps1'
'tests/Integration/DSC_SqlRS_Default.Integration.Tests.ps1'
'tests/Integration/DSC_SqlDatabaseUser.Integration.Tests.ps1'
'tests/Integration/DSC_SqlReplication.Integration.Tests.ps1'
'tests/Integration/DSC_SqlAudit.Integration.Tests.ps1'
Expand All @@ -237,6 +239,81 @@ stages:
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Integration ($(TEST_CONFIGURATION) / $(JOB_VMIMAGE))'

- job: Test_Integration_RS
displayName: 'Integration Reporting Services'
strategy:
matrix:
SQL2016_WIN2019:
JOB_VMIMAGE: 'windows-2019'
TEST_CONFIGURATION: 'Integration_SQL2016'
SQL2016_WIN2022:
JOB_VMIMAGE: 'windows-2022'
TEST_CONFIGURATION: 'Integration_SQL2016'
SQL2017_WIN2019:
JOB_VMIMAGE: 'windows-2019'
TEST_CONFIGURATION: 'Integration_SQL2017'
SQL2017_WIN2022:
JOB_VMIMAGE: 'windows-2022'
TEST_CONFIGURATION: 'Integration_SQL2017'
SQL2019_WIN2019:
JOB_VMIMAGE: 'windows-2019'
TEST_CONFIGURATION: 'Integration_SQL2019'
SQL2019_WIN2022:
JOB_VMIMAGE: 'windows-2022'
TEST_CONFIGURATION: 'Integration_SQL2019'
SQL2022_WIN2019:
JOB_VMIMAGE: 'windows-2019'
TEST_CONFIGURATION: 'Integration_SQL2022'
SQL2022_WIN2022:
JOB_VMIMAGE: 'windows-2022'
TEST_CONFIGURATION: 'Integration_SQL2022'
variables:
SKIP_DATABASE_ENGINE_DEFAULT_INSTANCE: true
SKIP_ANALYSIS_MULTI_INSTANCE: true
SKIP_ANALYSIS_TABULAR_INSTANCE: true
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: removeSqlServerModule
displayName: 'Remove SqlServer module'
- powershell: |
./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterTag $(TEST_CONFIGURATION) -PesterPath @(
# Run the integration tests in a specific group order.
# Group 1
'tests/Integration/DSC_SqlSetup.Integration.Tests.ps1'
# Group 2
'tests/Integration/DSC_SqlRSSetup.Integration.Tests.ps1'
# Group 3
'tests/Integration/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))'

- job: Code_Coverage
displayName: 'Publish Code Coverage'
dependsOn: Test_Unit
Expand Down
24 changes: 22 additions & 2 deletions source/Public/Import-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.DESCRIPTION
Imports the module SqlServer (preferred) or SQLPS in a standardized way.
The module is always imported globally.
.PARAMETER PreferredModule
Specifies the name of the preferred module. Defaults to 'SqlServer'.
Expand Down Expand Up @@ -100,7 +101,26 @@ function Import-SqlDscPreferredModule
PowerShell session environment variable PSModulePath to make sure it
contains all paths.
#>
Set-PSModulePath -Path ([System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'))

<#
Get the environment variables from all targets session, user and machine.
Casts the value to System.String to convert $null values to empty string.
#>
$modulePathSession = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath')
$modulePathUser = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath', 'User')
$modulePathMachine = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')

$modulePath = $modulePathSession + ';' + $modulePathUser + ';' + $modulePathMachine

$modulePathArray = $modulePath -split ';' |
Where-Object -FilterScript {
-not [System.String]::IsNullOrEmpty($_)
} |
Sort-Object -Unique

$modulePath = $modulePathArray -join ';'

Set-PSModulePath -Path $modulePath
}

# Get the newest SQLPS module if more than one exist.
Expand Down Expand Up @@ -134,7 +154,7 @@ function Import-SqlDscPreferredModule
SQLPS has unapproved verbs, disable checking to ignore Warnings.
Suppressing verbose so all cmdlet is not listed.
#>
$importedModule = Import-Module -Name $availableModuleName -DisableNameChecking -Verbose:$false -Force:$Force -PassThru -ErrorAction 'Stop'
$importedModule = Import-Module -Name $availableModuleName -DisableNameChecking -Verbose:$false -Force:$Force -Global -PassThru -ErrorAction 'Stop'

<#
SQLPS returns two entries, one with module type 'Script' and another with module type 'Manifest'.
Expand Down
Loading

0 comments on commit 67aa742

Please sign in to comment.