Skip to content

Commit f67dcac

Browse files
authored
Add integration test for Test-SqlDscIsSupportedFeature command (#2259)
1 parent 02de599 commit f67dcac

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Added integration tests for `Remove-SqlDscAudit` command to ensure it functions
1414
correctly in real environments
1515
[issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241).
16+
- Added integration tests for `Test-SqlDscIsSupportedFeature` command to ensure
17+
it functions correctly in real environments
18+
[issue #2228](https://github.com/dsccommunity/SqlServerDsc/issues/2228).
1619
- Added integration test for `Get-SqlDscManagedComputerService` command to ensure
1720
command reliability [issue #2219](https://github.com/dsccommunity/SqlServerDsc/issues/2219).
1821
- Added integration tests for `Set-SqlDscTraceFlag` command to ensure it functions

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ stages:
296296
'tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1'
297297
'tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1'
298298
'tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1'
299+
'tests/Integration/Commands/Test-SqlDscIsSupportedFeature.Integration.Tests.ps1'
299300
'tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1'
300301
'tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1'
301302
'tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1'

tests/Integration/Commands/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Assert-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTES
4747
New-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | IntegrationTestSqlLogin, SqlIntegrationTestGroup login
4848
Get-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
4949
Get-SqlDscConfigurationOption | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
50+
Test-SqlDscConfigurationOption | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
51+
Test-SqlDscIsSupportedFeature | 2 | 0 (Prerequisites) | - | -
5052
Get-SqlDscManagedComputer | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
5153
Get-SqlDscManagedComputerInstance | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
5254
Get-SqlDscManagedComputerService | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
2+
param ()
3+
4+
BeforeDiscovery {
5+
try
6+
{
7+
if (-not (Get-Module -Name 'DscResource.Test'))
8+
{
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
10+
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
11+
{
12+
# Redirect all streams to $null, except the error stream (stream 2)
13+
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
14+
}
15+
16+
# If the dependencies have not been resolved, this will throw an error.
17+
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
18+
}
19+
}
20+
catch [System.IO.FileNotFoundException]
21+
{
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
23+
}
24+
}
25+
26+
BeforeAll {
27+
$script:moduleName = 'SqlServerDsc'
28+
29+
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
30+
}
31+
32+
Describe 'Test-SqlDscIsSupportedFeature' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
33+
Context 'When testing supported features for different SQL Server versions' {
34+
It 'Should return $true for SQLENGINE feature across all major versions' {
35+
$testVersions = @('10', '11', '12', '13', '14', '15', '16')
36+
37+
foreach ($version in $testVersions) {
38+
$result = Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion $version -ErrorAction 'Stop'
39+
$result | Should -BeTrue -Because "SQLENGINE should be supported in SQL Server $version"
40+
}
41+
}
42+
43+
It 'Should return $false for features removed in SQL Server 2014 (version 14)' {
44+
$removedFeatures = @('RS', 'RS_SHP', 'RS_SHPWFE')
45+
46+
foreach ($feature in $removedFeatures) {
47+
$result = Test-SqlDscIsSupportedFeature -Feature $feature -ProductVersion '14' -ErrorAction 'Stop'
48+
$result | Should -BeFalse -Because "$feature was removed in SQL Server 2014"
49+
}
50+
}
51+
52+
It 'Should return $true for features removed in SQL Server 2014 when testing earlier versions' {
53+
$result = Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion '13' -ErrorAction 'Stop'
54+
$result | Should -BeTrue -Because "RS should be supported in SQL Server 2013"
55+
}
56+
57+
It 'Should return $false for features removed in SQL Server 2016 (version 16)' {
58+
$removedFeatures = @('Tools', 'BC', 'CONN', 'DREPLAY_CTLR', 'DREPLAY_CLT', 'SNAC_SDK', 'SDK', 'PolyBaseJava', 'SQL_INST_MR', 'SQL_INST_MPY', 'SQL_SHARED_MPY', 'SQL_SHARED_MR')
59+
60+
foreach ($feature in $removedFeatures) {
61+
$result = Test-SqlDscIsSupportedFeature -Feature $feature -ProductVersion '16' -ErrorAction 'Stop'
62+
$result | Should -BeFalse -Because "$feature was removed in SQL Server 2016"
63+
}
64+
}
65+
66+
It 'Should return $true for features added in SQL Server 2015 (version 15) when testing that version' {
67+
$addedFeatures = @('PolyBaseCore', 'PolyBaseJava', 'SQL_INST_JAVA')
68+
69+
foreach ($feature in $addedFeatures) {
70+
$result = Test-SqlDscIsSupportedFeature -Feature $feature -ProductVersion '15' -ErrorAction 'Stop'
71+
$result | Should -BeTrue -Because "$feature was added in SQL Server 2015"
72+
}
73+
}
74+
75+
It 'Should return $false for features added in SQL Server 2015 when testing earlier versions' {
76+
$result = Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion '14' -ErrorAction 'Stop'
77+
$result | Should -BeFalse -Because "PolyBaseCore was not available in SQL Server 2014"
78+
}
79+
}
80+
81+
Context 'When using pipeline input' {
82+
It 'Should accept feature names from pipeline and return single result based on last processed item' {
83+
# The current implementation has a limitation where pipeline input only returns one result
84+
# This test validates the current behavior
85+
$features = @('SQLENGINE', 'AS', 'IS')
86+
87+
$result = $features | Test-SqlDscIsSupportedFeature -ProductVersion '15' -ErrorAction 'Stop'
88+
89+
$result | Should -BeOfType 'System.Boolean'
90+
$result | Should -BeTrue -Because "The last feature processed should be supported in SQL Server 2015"
91+
}
92+
93+
It 'Should return false when last feature in pipeline is unsupported' {
94+
# Test with a mix where the last feature is unsupported
95+
$features = @('SQLENGINE', 'RS') # RS is not supported in version 14
96+
97+
$result = $features | Test-SqlDscIsSupportedFeature -ProductVersion '14' -ErrorAction 'Stop'
98+
99+
$result | Should -BeFalse -Because "RS (the last feature) is not supported in SQL Server 2014"
100+
}
101+
}
102+
103+
Context 'When testing edge cases' {
104+
It 'Should handle major version only input' {
105+
$result = Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion '15' -ErrorAction 'Stop'
106+
$result | Should -BeTrue
107+
}
108+
109+
It 'Should handle full version string input' {
110+
$result = Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion '15.0.2000.5' -ErrorAction 'Stop'
111+
$result | Should -BeTrue
112+
}
113+
114+
It 'Should be case insensitive for feature names' {
115+
$resultLower = Test-SqlDscIsSupportedFeature -Feature 'sqlengine' -ProductVersion '15' -ErrorAction 'Stop'
116+
$resultUpper = Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion '15' -ErrorAction 'Stop'
117+
$resultMixed = Test-SqlDscIsSupportedFeature -Feature 'SqlEngine' -ProductVersion '15' -ErrorAction 'Stop'
118+
119+
$resultLower | Should -Be $resultUpper
120+
$resultUpper | Should -Be $resultMixed
121+
$resultLower | Should -BeTrue
122+
}
123+
124+
It 'Should handle very high version numbers' {
125+
$result = Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion '999' -ErrorAction 'Stop'
126+
$result | Should -BeTrue -Because "SQLENGINE should be supported in future versions"
127+
}
128+
}
129+
130+
Context 'When testing specific feature version dependencies' {
131+
It 'Should correctly identify PolyBaseJava as version-specific' {
132+
# PolyBaseJava was added in version 15 but removed in version 16
133+
$resultV14 = Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion '14' -ErrorAction 'Stop'
134+
$resultV15 = Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion '15' -ErrorAction 'Stop'
135+
$resultV16 = Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion '16' -ErrorAction 'Stop'
136+
137+
$resultV14 | Should -BeFalse -Because "PolyBaseJava was not available before SQL Server 2015"
138+
$resultV15 | Should -BeTrue -Because "PolyBaseJava was available in SQL Server 2015"
139+
$resultV16 | Should -BeFalse -Because "PolyBaseJava was removed in SQL Server 2016"
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)