|
| 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