Skip to content

Commit dfe01bc

Browse files
authored
Add SQL Server 2025 to integration tests (#2435)
1 parent 49b5991 commit dfe01bc

File tree

145 files changed

+388
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+388
-160
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- SqlServerDsc.Common
1111
- Moved functions into individual files and use ModuleBuilder to assemble.
12-
1312
- SqlServerDsc
1413
- Refactor integration tests for _SQL Server Reporting Services_ and _Power BI_
1514
_Report Server_ ([issue #2431](https://github.com/dsccommunity/SqlServerDsc/issues/2431)).
1615
- `Connect-Sql` create connection and server objects as per documentation.
1716
- `Invoke-SqlDscQuery` remove disconnect as there is not an explicit connect.
17+
- Add SQL Server 2025 to integration tests ([issue #2427](https://github.com/dsccommunity/SqlServerDsc/issues/2427)).
1818

1919
### Fixed
2020

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ To make sure a integration tests is run in the correct order the integration
282282
tests are grouped in the file `azure-pipelines.yml` in the integration tests
283283
jobs.
284284

285-
There are three, separate, integration tests jobs that each, independently, test
286-
SQL Server 2016, SQL Server 2017 and SQL Server 2019.
285+
There are multiple, separate integration test jobs that independently test SQL Server 2017, SQL Server 2019, SQL Server 2022 and SQL Server 2025.
287286

288287
### Testing of examples files
289288

azure-pipelines.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ stages:
283283
SQL2022_WIN2025:
284284
JOB_VMIMAGE: 'windows-2025'
285285
TEST_CONFIGURATION: 'Integration_SQL2022'
286+
SQL2025_WIN2025:
287+
JOB_VMIMAGE: 'windows-2025'
288+
TEST_CONFIGURATION: 'Integration_SQL2025'
286289
pool:
287290
vmImage: $(JOB_VMIMAGE)
288291
timeoutInMinutes: '0'
@@ -452,6 +455,9 @@ stages:
452455
SQL2022_WIN2025:
453456
JOB_VMIMAGE: 'windows-2025'
454457
TEST_CONFIGURATION: 'Integration_SQL2022'
458+
SQL2025_WIN2025:
459+
JOB_VMIMAGE: 'windows-2025'
460+
TEST_CONFIGURATION: 'Integration_SQL2025'
455461
pool:
456462
vmImage: $(JOB_VMIMAGE)
457463
timeoutInMinutes: '0'
@@ -846,6 +852,9 @@ stages:
846852
SQL2022_WIN2025:
847853
JOB_VMIMAGE: 'windows-2025'
848854
TEST_CONFIGURATION: 'Integration_SQL2022'
855+
SQL2025_WIN2025:
856+
JOB_VMIMAGE: 'windows-2025'
857+
TEST_CONFIGURATION: 'Integration_SQL2025'
849858
pool:
850859
vmImage: $(JOB_VMIMAGE)
851860
timeoutInMinutes: '0'
@@ -938,6 +947,9 @@ stages:
938947
SQL2022_WIN2022:
939948
JOB_VMIMAGE: 'windows-2022'
940949
TEST_CONFIGURATION: 'Integration_SQL2022'
950+
SQL2025_WIN2025:
951+
JOB_VMIMAGE: 'windows-2025'
952+
TEST_CONFIGURATION: 'Integration_SQL2025'
941953
pool:
942954
vmImage: $(JOB_VMIMAGE)
943955
timeoutInMinutes: '0'
@@ -1254,6 +1266,9 @@ stages:
12541266
SQL2022_WIN2022:
12551267
JOB_VMIMAGE: 'windows-2022'
12561268
TEST_CONFIGURATION: 'Integration_SQL2022'
1269+
SQL2025_WIN2025:
1270+
JOB_VMIMAGE: 'windows-2025'
1271+
TEST_CONFIGURATION: 'Integration_SQL2025'
12571272
pool:
12581273
vmImage: $(JOB_VMIMAGE)
12591274
timeoutInMinutes: 0

source/Classes/020.SqlDatabase.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class SqlDatabase : SqlResourceBase
337337
$Collation
338338

339339
[DscProperty()]
340-
[ValidateSet('Version80', 'Version90', 'Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160')]
340+
[ValidateSet('Version80', 'Version90', 'Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160', 'Version170')]
341341
[System.String]
342342
$CompatibilityLevel
343343

@@ -745,7 +745,21 @@ class SqlDatabase : SqlResourceBase
745745
# Only set CompatibilityLevel if it's a valid non-zero value
746746
if ($databaseObject.CompatibilityLevel -gt 0)
747747
{
748-
$currentState.CompatibilityLevel = $databaseObject.CompatibilityLevel.ToString()
748+
$compatValue = $databaseObject.CompatibilityLevel.ToString()
749+
750+
<#
751+
SMO may return numeric values (e.g. 170 for SQL Server 2025).
752+
Convert purely-numeric values to the 'Version' prefixed form
753+
so they match the ValidateSet values (Version80..Version170).
754+
#>
755+
if ($compatValue -match '^[0-9]+$')
756+
{
757+
$currentState.CompatibilityLevel = 'Version{0}' -f $compatValue
758+
}
759+
else
760+
{
761+
$currentState.CompatibilityLevel = $compatValue
762+
}
749763
}
750764

751765
$currentState.RecoveryModel = $databaseObject.RecoveryModel.ToString()

source/DSCResources/DSC_SqlReplication/DSC_SqlReplication.psm1

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ function Set-TargetResource
287287
Install-RemoteDistributor `
288288
-ReplicationServer $localReplicationServer `
289289
-RemoteDistributor $RemoteDistributor `
290-
-AdminLinkCredentials $AdminLinkCredentials
290+
-AdminLinkCredentials $AdminLinkCredentials `
291+
-InstanceName $InstanceName
291292
}
292293
}
293294
else #'Absent'
@@ -437,7 +438,7 @@ function New-ServerConnection
437438
$SqlServerName
438439
)
439440

440-
if ($SqlMajorVersion -eq 16)
441+
if ($SqlMajorVersion -in @(16, 17))
441442
{
442443
<#
443444
For SQL Server 2022 the object must be created with New-Object and
@@ -598,6 +599,9 @@ function New-DistributionPublisher
598599
.PARAMETER AdminLinkCredentials
599600
AdminLink password to be used when setting up publisher distributor
600601
relationship.
602+
603+
.PARAMETER InstanceName
604+
SQL Server instance name where replication distribution will be configured.
601605
#>
602606
function Install-RemoteDistributor
603607
{
@@ -614,22 +618,50 @@ function Install-RemoteDistributor
614618

615619
[Parameter(Mandatory = $true)]
616620
[System.Management.Automation.PSCredential]
617-
$AdminLinkCredentials
621+
$AdminLinkCredentials,
622+
623+
[Parameter(Mandatory = $true)]
624+
[System.String]
625+
$InstanceName
618626
)
619627

620628
Write-Verbose -Message (
621629
$script:localizedData.InstallRemoteDistributor -f $RemoteDistributor
622630
)
623631

624-
try
632+
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName $InstanceName -ErrorAction 'Stop'
633+
634+
$sqlMajorVersion = $serverObject.VersionMajor
635+
636+
if ($sqlMajorVersion -eq 17)
625637
{
626-
$ReplicationServer.InstallDistributor($RemoteDistributor, $AdminLinkCredentials.Password)
638+
$clearTextPassword = $AdminLinkCredentials.GetNetworkCredential().Password
639+
640+
<#
641+
Need to execute stored procedure sp_adddistributor for SQL Server 2025.
642+
Workaround for issue: https://github.com/dsccommunity/SqlServerDsc/pull/2435#issuecomment-3796616952
643+
644+
TODO: Should support encrypted connection in the future, then we could
645+
probably go back to using InstallDistributor(), another option is
646+
to move to stored procedures for all of the Replication logic.
647+
#>
648+
$query = "EXECUTE sys.sp_adddistributor @distributor = N'$RemoteDistributor', @password = N'$clearTextPassword', @encrypt_distributor_connection = 'optional', @trust_distributor_certificate = 'yes';"
649+
650+
# TODO: This need to pass a credential in the future, now connects using the one resource is run as.
651+
Invoke-SqlDscQuery -ServerObject $serverObject -DatabaseName 'master' -Query $query -RedactText $clearTextPassword -Force -ErrorAction 'Stop'
627652
}
628-
catch
653+
else
629654
{
630-
$errorMessage = $script:localizedData.FailedInFunction -f 'Install-RemoteDistributor'
655+
try
656+
{
657+
$ReplicationServer.InstallDistributor($RemoteDistributor, $AdminLinkCredentials.Password)
658+
}
659+
catch
660+
{
661+
$errorMessage = $script:localizedData.FailedInFunction -f 'Install-RemoteDistributor'
631662

632-
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
663+
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
664+
}
633665
}
634666
}
635667

source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ function Set-TargetResource
11191119
# If SQL shared components already installed, clear InstallShared*Dir variables
11201120
switch ($SqlVersion)
11211121
{
1122-
{ $_ -in ('10', '11', '12', '13', '14', '15', '16') }
1122+
{ $_ -in ('10', '11', '12', '13', '14', '15', '16', '17') }
11231123
{
11241124
if ((Get-Variable -Name 'InstallSharedDir' -ErrorAction SilentlyContinue) -and (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\FEE2E540D20152D4597229B6CFBC0A69' -ErrorAction SilentlyContinue))
11251125
{
@@ -3387,7 +3387,7 @@ function Get-SqlSharedPaths
33873387

33883388
switch ($SqlServerMajorVersion)
33893389
{
3390-
{ $_ -in ('10', '11', '12', '13', '14', '15', '16') }
3390+
{ $_ -in ('10', '11', '12', '13', '14', '15', '16', '17') }
33913391
{
33923392
$registryKeySharedDir = 'FEE2E540D20152D4597229B6CFBC0A69'
33933393
$registryKeySharedWOWDir = 'A79497A344129F64CA7D69C56F5DD8B4'

source/Public/New-SqlDscDatabase.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function New-SqlDscDatabase
368368
$CatalogCollation,
369369

370370
[Parameter(ParameterSetName = 'Database')]
371-
[ValidateSet('Version80', 'Version90', 'Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160')]
371+
[ValidateSet('Version80', 'Version90', 'Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160', 'Version170')]
372372
[System.String]
373373
$CompatibilityLevel,
374374

@@ -738,6 +738,7 @@ function New-SqlDscDatabase
738738
14 = @('Version100', 'Version110', 'Version120', 'Version130', 'Version140')
739739
15 = @('Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150')
740740
16 = @('Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160')
741+
17 = @('Version100', 'Version110', 'Version120', 'Version130', 'Version140', 'Version150', 'Version160', 'Version170')
741742
}
742743

743744
if ($CompatibilityLevel -notin $supportedCompatibilityLevels.$($ServerObject.VersionMajor))

tests/Integration/Commands/Add-SqlDscFileGroup.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BeforeAll {
3131
Import-Module -Name $script:moduleName -ErrorAction 'Stop'
3232
}
3333

34-
Describe 'Add-SqlDscFileGroup' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
34+
Describe 'Add-SqlDscFileGroup' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_SQL2025') {
3535
BeforeAll {
3636
$script:mockInstanceName = 'DSCSQLTEST'
3737
$script:mockComputerName = Get-ComputerName

tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BeforeAll {
3131
Import-Module -Name $script:moduleName -ErrorAction 'Stop'
3232
}
3333

34-
Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
34+
Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_SQL2025') {
3535
BeforeAll {
3636
$script:mockInstanceName = 'DSCSQLTEST'
3737
$script:mockComputerName = Get-ComputerName

tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AfterAll {
4040
$null = Remove-Item -Path 'Env:\SqlServerDscCI' -ErrorAction 'Stop'
4141
}
4242

43-
Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
43+
Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022', 'Integration_SQL2025' {
4444
BeforeAll {
4545
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
4646
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

0 commit comments

Comments
 (0)