From 48ea21916ed172ce36ebb98f06a03b2c64e440d9 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 11 Jan 2019 15:07:15 +0100 Subject: [PATCH 01/18] Changes to SqlServerDsc - Reverting the change that was made as part of the issue #1260 in the previous release, as it only mitigated the issue, it did not solve the issue. --- CHANGELOG.md | 5 +++++ appveyor.yml | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002d49421..2761e64cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ - Changes to SqlServerLogin - Fixed issue in Test-TargetResource to valid password on disabled accounts. ([issue #915](https://github.com/PowerShell/SqlServerDsc/issues/915)). +- Changes to SqlServerDsc + - Reverting the change that was made as part of the + [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260) + in the previous release, as it only mitigated the issue, it did not + solve the issue. ## 12.2.0.0 diff --git a/appveyor.yml b/appveyor.yml index d6acc116a..d890750f8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,9 +5,6 @@ version: 9.0.{build}.0 image: Visual Studio 2017 install: - git clone https://github.com/PowerShell/DscResource.Tests - - ps: Start-Sleep -Seconds 5 - - ps: Restart-Computer -Force - - ps: Start-Sleep -Seconds 5 - ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - ps: Invoke-AppveyorInstallTask From db27c54b72747f581ff2c2b9a775bf5776e1bb08 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 11 Jan 2019 17:02:45 +0100 Subject: [PATCH 02/18] Changes to SqlSetup - Updated the integration test to stop the named instance while installing the other instances to mitigate issue #1260. --- CHANGELOG.md | 4 ++ .../MSFT_SqlSetup.Integration.Tests.ps1 | 37 ++++++++++++++++++- Tests/Integration/MSFT_SqlSetup.config.ps1 | 31 +++++++++++++--- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2761e64cd..5525b5e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260) in the previous release, as it only mitigated the issue, it did not solve the issue. +- Changes to SqlSetup + - Updated the integration test to stop the named instance while installing + the other instances to mitigate + [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260). ## 12.2.0.0 diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index f542dc88d..f9ac12900 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -317,7 +317,7 @@ try } } - $configurationName = "$($script:DSCResourceName)_StopMultiAnalysisServicesInstance_Config" + $configurationName = "$($script:DSCResourceName)_StopServicesInstance_Config" Context ('When using configuration {0}' -f $configurationName) { It 'Should compile and apply the MOF without throwing' { @@ -654,6 +654,41 @@ try } | Should -Not -Throw } } + + $configurationName = "$($script:DSCResourceName)_StartServicesInstance_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + try + { + Start-DscConfiguration @startDscConfigurationParameters + } + catch + { + Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose + throw $_ + } + } | Should -Not -Throw + } + } } } finally diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index aef829505..15351b54d 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -231,17 +231,21 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config } } -Configuration MSFT_SqlSetup_StopMultiAnalysisServicesInstance_Config +Configuration MSFT_SqlSetup_StopServicesInstance_Config { Import-DscResource -ModuleName 'PSDscResources' node localhost { - # Service ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) - # { - # Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) - # State = 'Stopped' - # } + <# + Stopping the Database Engine named instance. It will be restarted + at the end of the tests. + #> + Service ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + { + Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) + State = 'Stopped' + } Service ('StopMultiAnalysisServicesInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { @@ -383,3 +387,18 @@ Configuration MSFT_SqlSetup_StopTabularAnalysisServices_Config } } } + +Configuration MSFT_SqlSetup_StartServicesInstance_Config +{ + Import-DscResource -ModuleName 'PSDscResources' + + node localhost + { + # Start the Database Engine named instance. + Service ('StartSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + { + Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) + State = 'Running' + } + } +} From dae487fa5afe1124eaec4a806097684a5e392d3f Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 11 Jan 2019 18:12:23 +0100 Subject: [PATCH 03/18] Stop and restart SQL Server Agent --- Tests/Integration/MSFT_SqlSetup.config.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 15351b54d..784fc1523 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -237,6 +237,16 @@ Configuration MSFT_SqlSetup_StopServicesInstance_Config node localhost { + <# + Stopping the SQL Server Agent service for the named instance. + It will be restarted at the end of the tests. + #> + Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + { + Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) + State = 'Stopped' + } + <# Stopping the Database Engine named instance. It will be restarted at the end of the tests. @@ -400,5 +410,14 @@ Configuration MSFT_SqlSetup_StartServicesInstance_Config Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Running' } + + <# + Starting the SQL Server Agent service for the named instance. + #> + Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + { + Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) + State = 'Running' + } } } From b9294e0c6e8fedad85f08fd0131b9098b2569fff Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 15 Jan 2019 17:58:36 +0100 Subject: [PATCH 04/18] Fix comment --- Tests/Integration/MSFT_SqlSetup.config.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 784fc1523..48658a81b 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -411,9 +411,7 @@ Configuration MSFT_SqlSetup_StartServicesInstance_Config State = 'Running' } - <# - Starting the SQL Server Agent service for the named instance. - #> + # Starting the SQL Server Agent service for the named instance. Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) From 998d5f220a943b0729a385c71cfa3e6052f95a37 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 15 Jan 2019 18:01:00 +0100 Subject: [PATCH 05/18] Reorder CHANGELOG.md --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5525b5e4d..466c115d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +- Changes to SqlServerDsc + - Reverting the change that was made as part of the + [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260) + in the previous release, as it only mitigated the issue, it did not + solve the issue. - Changes to SqlServiceAccount - Fixed Get-ServiceObject when searching for Integration Services service. Unlike the rest of SQL Server services, the Integration Services service @@ -14,11 +19,6 @@ - Changes to SqlServerLogin - Fixed issue in Test-TargetResource to valid password on disabled accounts. ([issue #915](https://github.com/PowerShell/SqlServerDsc/issues/915)). -- Changes to SqlServerDsc - - Reverting the change that was made as part of the - [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260) - in the previous release, as it only mitigated the issue, it did not - solve the issue. - Changes to SqlSetup - Updated the integration test to stop the named instance while installing the other instances to mitigate From da8c65fa10c6d90cc7eec72ec188fb60513111b0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 16 Jan 2019 11:45:49 +0100 Subject: [PATCH 06/18] Fix review comments at r1 --- .../MSFT_SqlSetup.Integration.Tests.ps1 | 72 ++----------------- Tests/Integration/MSFT_SqlSetup.config.ps1 | 2 +- 2 files changed, 8 insertions(+), 66 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index f9ac12900..bde41c48b 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -26,8 +26,6 @@ $TestEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:DSCModuleName ` -DSCResourceName $script:DSCResourceName ` -TestType Integration - -$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:' #endregion <# @@ -186,15 +184,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -339,15 +329,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -378,15 +360,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } -ErrorVariable itBlockError @@ -494,15 +468,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -532,15 +498,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } -ErrorVariable itBlockError @@ -642,15 +600,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -677,15 +627,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 48658a81b..9556c2d51 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -412,7 +412,7 @@ Configuration MSFT_SqlSetup_StartServicesInstance_Config } # Starting the SQL Server Agent service for the named instance. - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + Service ('StartSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Running' From ff21cbc81b0a12b4c9d8fac230386dc156af415a Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 16 Jan 2019 15:05:55 +0100 Subject: [PATCH 07/18] Added UpdateSource to install Service Pack 2 --- .../Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 12 ++++++++++++ Tests/Integration/MSFT_SqlSetup.config.ps1 | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index bde41c48b..a013c0e13 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -101,15 +101,27 @@ try $mockForceReboot = $ConfigurationData.AllNodes.ForceReboot $mockIsoMediaFilePath = $ConfigurationData.AllNodes.ImagePath $mockIsoMediaDriveLetter = $ConfigurationData.AllNodes.DriveLetter + $mockServicePackMediaFilePath = $ConfigurationData.AllNodes.ImagePathServicePack $mockSourceMediaUrl = 'https://download.microsoft.com/download/9/0/7/907AD35F-9F9C-43A5-9789-52470555DB90/ENU/SQLServer2016SP1-FullSlipstream-x64-ENU.iso' + $mockServicePackMediaUrl = 'https://download.microsoft.com/download/9/2/B/92BAD988-00C5-4F68-811E-B7FFBE009B00/SQLServer2016SP2-KB4052908-x64-ENU.exe' # Download SQL Server media if (-not (Test-Path -Path $mockIsoMediaFilePath)) { Write-Verbose -Message "Start downloading the SQL Server media iso at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose + # Create the Updates folder + New-Item -ItemType Directory -Path (Split-Path -Path $mockServicePackMediaFilePath -Parent) -Force + + # By switching to 'SilentlyContinue' should theoretically increase the download speed. + $previousProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest -Uri $mockSourceMediaUrl -OutFile $mockIsoMediaFilePath + Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath + + $ProgressPreference = $previousProgressPreference # Double check that the SQL media was downloaded. if (-not (Test-Path -Path $mockIsoMediaFilePath)) diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 9556c2d51..ba232de0f 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -37,12 +37,14 @@ $ConfigurationData = @{ Collation = 'Finnish_Swedish_CI_AS' InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - UpdateEnabled = 'False' + UpdateEnabled = 'True' + UpdateSource = "$env:TEMP\SqlUpdates" SuppressReboot = $true # Make sure we don't reboot during testing. ForceReboot = $false # Properties for mounting media ImagePath = "$env:TEMP\SQL2016.iso" + ImagePathServicePack = "$env:TEMP\SqlUpdates\SQLServer2016SP2-KB4052908-x64-ENU.exe" DriveLetter = $mockIsoMediaDriveLetter CertificateFile = $env:DscPublicCertificatePath @@ -210,6 +212,7 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled + UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot @@ -305,6 +308,7 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineDefaultInstanceAsUser_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled + UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot SQLSysAdminAccounts = @( @@ -373,6 +377,7 @@ Configuration MSFT_SqlSetup_InstallTabularAnalysisServicesAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled + UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot From b04ad7c627805a5b1457974d0433e610e28556de Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 16 Jan 2019 15:29:17 +0100 Subject: [PATCH 08/18] Add the hash in the verbose messages --- Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index a013c0e13..9d329e5bb 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -109,8 +109,6 @@ try # Download SQL Server media if (-not (Test-Path -Path $mockIsoMediaFilePath)) { - Write-Verbose -Message "Start downloading the SQL Server media iso at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose - # Create the Updates folder New-Item -ItemType Directory -Path (Split-Path -Path $mockServicePackMediaFilePath -Parent) -Force @@ -118,8 +116,16 @@ try $previousProgressPreference = $ProgressPreference $ProgressPreference = 'SilentlyContinue' + Write-Verbose -Message "Start downloading the SQL Server media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose + Invoke-WebRequest -Uri $mockSourceMediaUrl -OutFile $mockIsoMediaFilePath + + Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath).Hash) -Verbose + + Write-Verbose -Message "Start downloading the SQL Server Service Pack media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose + Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath + Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath).Hash) -Verbose $ProgressPreference = $previousProgressPreference From 6375da4bfde30ca3d330080597831bb858abcd0c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 19 Jan 2019 12:15:29 +0100 Subject: [PATCH 09/18] Revert UpdateSource to install Service Pack 2 --- .../Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 12 ++++++------ Tests/Integration/MSFT_SqlSetup.config.ps1 | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index 9d329e5bb..63e88c22a 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -101,16 +101,16 @@ try $mockForceReboot = $ConfigurationData.AllNodes.ForceReboot $mockIsoMediaFilePath = $ConfigurationData.AllNodes.ImagePath $mockIsoMediaDriveLetter = $ConfigurationData.AllNodes.DriveLetter - $mockServicePackMediaFilePath = $ConfigurationData.AllNodes.ImagePathServicePack + #$mockServicePackMediaFilePath = $ConfigurationData.AllNodes.ImagePathServicePack $mockSourceMediaUrl = 'https://download.microsoft.com/download/9/0/7/907AD35F-9F9C-43A5-9789-52470555DB90/ENU/SQLServer2016SP1-FullSlipstream-x64-ENU.iso' - $mockServicePackMediaUrl = 'https://download.microsoft.com/download/9/2/B/92BAD988-00C5-4F68-811E-B7FFBE009B00/SQLServer2016SP2-KB4052908-x64-ENU.exe' + #$mockServicePackMediaUrl = 'https://download.microsoft.com/download/9/2/B/92BAD988-00C5-4F68-811E-B7FFBE009B00/SQLServer2016SP2-KB4052908-x64-ENU.exe' # Download SQL Server media if (-not (Test-Path -Path $mockIsoMediaFilePath)) { # Create the Updates folder - New-Item -ItemType Directory -Path (Split-Path -Path $mockServicePackMediaFilePath -Parent) -Force + #New-Item -ItemType Directory -Path (Split-Path -Path $mockServicePackMediaFilePath -Parent) -Force # By switching to 'SilentlyContinue' should theoretically increase the download speed. $previousProgressPreference = $ProgressPreference @@ -122,10 +122,10 @@ try Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath).Hash) -Verbose - Write-Verbose -Message "Start downloading the SQL Server Service Pack media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose + #Write-Verbose -Message "Start downloading the SQL Server Service Pack media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose - Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath - Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath).Hash) -Verbose + #Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath + #Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath).Hash) -Verbose $ProgressPreference = $previousProgressPreference diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index ba232de0f..121659f1a 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -37,14 +37,14 @@ $ConfigurationData = @{ Collation = 'Finnish_Swedish_CI_AS' InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - UpdateEnabled = 'True' - UpdateSource = "$env:TEMP\SqlUpdates" + UpdateEnabled = 'False' + #UpdateSource = "$env:TEMP\SqlUpdates" SuppressReboot = $true # Make sure we don't reboot during testing. ForceReboot = $false # Properties for mounting media ImagePath = "$env:TEMP\SQL2016.iso" - ImagePathServicePack = "$env:TEMP\SqlUpdates\SQLServer2016SP2-KB4052908-x64-ENU.exe" + #ImagePathServicePack = "$env:TEMP\SqlUpdates\SQLServer2016SP2-KB4052908-x64-ENU.exe" DriveLetter = $mockIsoMediaDriveLetter CertificateFile = $env:DscPublicCertificatePath @@ -212,7 +212,7 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - UpdateSource = $Node.UpdateSource + #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot @@ -308,7 +308,7 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineDefaultInstanceAsUser_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - UpdateSource = $Node.UpdateSource + #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot SQLSysAdminAccounts = @( @@ -377,7 +377,7 @@ Configuration MSFT_SqlSetup_InstallTabularAnalysisServicesAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - UpdateSource = $Node.UpdateSource + #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot From d6ba730443df52090df8d1eebdfa1060f13e76bc Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 19 Jan 2019 12:34:55 +0100 Subject: [PATCH 10/18] Change to SHA384 hash --- Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index 63e88c22a..b45322b98 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -120,12 +120,12 @@ try Invoke-WebRequest -Uri $mockSourceMediaUrl -OutFile $mockIsoMediaFilePath - Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath).Hash) -Verbose + Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath -Algorithm 'SHA384').Hash) -Verbose #Write-Verbose -Message "Start downloading the SQL Server Service Pack media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose #Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath - #Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath).Hash) -Verbose + #Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath -Algorithm SHA384).Hash) -Verbose $ProgressPreference = $previousProgressPreference From 3644c4a390338204ea057c14594a6e951b81b82a Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 10:38:22 +0100 Subject: [PATCH 11/18] Run parallel testing (in sequence on free accounts) --- ...T_SqlAlwaysOnService.Integration.Tests.ps1 | 6 ++++ ...abaseDefaultLocation.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlRS.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlScript.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlScriptQuery.Integration.Tests.ps1 | 6 ++++ ...qlServerDatabaseMail.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlServerLogin.Integration.Tests.ps1 | 6 ++++ ...SFT_SqlServerNetwork.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlServerRole.Integration.Tests.ps1 | 6 ++++ ...rverSecureConnection.Integration.Tests.ps1 | 6 ++++ ...FT_SqlServiceAccount.Integration.Tests.ps1 | 6 ++++ .../MSFT_SqlSetup.Integration.Tests.ps1 | 6 ++++ Tests/Unit/CommonResourceHelper.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlAG.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlAGListener.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 | 12 ++++++-- Tests/Unit/MSFT_SqlAlias.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlDatabase.Tests.ps1 | 10 ++++--- .../MSFT_SqlDatabaseDefaultLocation.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 | 10 ++++--- .../Unit/MSFT_SqlDatabasePermission.Tests.ps1 | 10 ++++--- .../MSFT_SqlDatabaseRecoveryModel.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlRS.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlScript.Tests.ps1 | 11 +++++-- Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 | 11 +++++-- .../MSFT_SqlServerConfiguration.Tests.ps1 | 9 ++++-- .../Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 | 10 ++++--- ...MSFT_SqlServerEndpointPermission.Tests.ps1 | 10 ++++--- .../MSFT_SqlServerEndpointState.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 | 30 +++++++++++-------- Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 | 10 ++++--- .../Unit/MSFT_SqlServerReplication.Tests.ps1 | 8 +++-- Tests/Unit/MSFT_SqlServerRole.Tests.ps1 | 10 ++++--- .../MSFT_SqlServerSecureConnection.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 | 16 +++++----- Tests/Unit/MSFT_SqlSetup.Tests.ps1 | 8 +++-- Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 | 10 ++++--- Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 | 11 +++++-- Tests/Unit/SqlServerDSCHelper.Tests.ps1 | 18 ++++++----- appveyor.yml | 3 ++ 47 files changed, 319 insertions(+), 135 deletions(-) diff --git a/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 index 6d49d9cb3..cfc8ecb53 100644 --- a/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 index ccfac6198..5f4e1711d 100644 --- a/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 index 88f3b33cd..38a0b7f5e 100644 --- a/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlScript.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlScript.Integration.Tests.ps1 index bbba95568..96f2ffa6d 100644 --- a/Tests/Integration/MSFT_SqlScript.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlScript.Integration.Tests.ps1 @@ -17,6 +17,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlScriptQuery.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlScriptQuery.Integration.Tests.ps1 index 22c7d4f59..e3ce77b68 100644 --- a/Tests/Integration/MSFT_SqlScriptQuery.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlScriptQuery.Integration.Tests.ps1 @@ -17,6 +17,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 index b232831aa..da5a2bf9a 100644 --- a/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServerLogin.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServerLogin.Integration.Tests.ps1 index 5c0273773..f4506483e 100644 --- a/Tests/Integration/MSFT_SqlServerLogin.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServerLogin.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServerNetwork.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServerNetwork.Integration.Tests.ps1 index 26bab827b..ced9220a4 100644 --- a/Tests/Integration/MSFT_SqlServerNetwork.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServerNetwork.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServerRole.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServerRole.Integration.Tests.ps1 index e10cc609e..d7278852d 100644 --- a/Tests/Integration/MSFT_SqlServerRole.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServerRole.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServerSecureConnection.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServerSecureConnection.Integration.Tests.ps1 index 7d39536ce..42f4fa10c 100644 --- a/Tests/Integration/MSFT_SqlServerSecureConnection.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServerSecureConnection.Integration.Tests.ps1 @@ -17,6 +17,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 index 4a2bf7d32..5adaa576a 100644 --- a/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index b45322b98..655683cbd 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -12,6 +12,12 @@ if (-not $env:APPVEYOR -eq $true) return } +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Integration') +{ + Write-Verbose -Message ('Integration test for {0} will be skipped unless $env:CONFIGURATION is set to ''Integration''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Integration Test Template Version: 1.1.2 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Unit/CommonResourceHelper.Tests.ps1 b/Tests/Unit/CommonResourceHelper.Tests.ps1 index 6a69d0ffe..643ecfa08 100644 --- a/Tests/Unit/CommonResourceHelper.Tests.ps1 +++ b/Tests/Unit/CommonResourceHelper.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() + +$script:helperModuleName = 'CommonResourceHelper' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:helperModuleName) -Verbose + return +} Describe 'CommonResourceHelper Unit Tests' { BeforeAll { diff --git a/Tests/Unit/MSFT_SqlAG.Tests.ps1 b/Tests/Unit/MSFT_SqlAG.Tests.ps1 index 26f787015..f096adac4 100644 --- a/Tests/Unit/MSFT_SqlAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAG.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAG' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} #region HEADER diff --git a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 index b6ccbb3a9..2a6582f76 100644 --- a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAGDatabase' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} #region HEADER diff --git a/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 index 5150c71c0..2b798b436 100644 --- a/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlAGListener' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 index ba16315cd..f514d81e7 100644 --- a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 @@ -8,9 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAGReplica' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER diff --git a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 index a02551ec0..788caf580 100644 --- a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAlias' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} #region HEADER diff --git a/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 index 29dd82fee..d7319bbe9 100644 --- a/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlAlwaysOnService' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + # Unit Test Template Version: 1.1.0 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` diff --git a/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 index b14acc183..fe7d16e63 100644 --- a/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlDatabase' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 index 0dc41e661..67e656ee5 100644 --- a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabaseDefaultLocation' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} #region Header diff --git a/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 index 961c259ef..894a1886a 100644 --- a/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlDatabaseOwner' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 index 01dd6672d..90e49b118 100644 --- a/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlDatabasePermission' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 index d1a8ee4fc..a912d1ce7 100644 --- a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlDatabaseRecoveryModel' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 index 4eb18da38..636fa97f9 100644 --- a/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlDatabaseRole' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlRS.Tests.ps1 b/Tests/Unit/MSFT_SqlRS.Tests.ps1 index abc35f536..25c7b8627 100644 --- a/Tests/Unit/MSFT_SqlRS.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlRS.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlRS' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlScript.Tests.ps1 b/Tests/Unit/MSFT_SqlScript.Tests.ps1 index 9e746e75f..4cd199901 100644 --- a/Tests/Unit/MSFT_SqlScript.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScript.Tests.ps1 @@ -8,12 +8,19 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] # Suppression of this PSSA rule allowed in tests. [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlScript' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 b/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 index 75ec443c0..1861e9669 100644 --- a/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 @@ -8,12 +8,19 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] # Suppression of this PSSA rule allowed in tests. [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] Param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlScriptQuery' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 index 67fcb2b5d..36d163246 100644 --- a/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 @@ -8,13 +8,16 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerConfiguration' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + # Unit Test Template Version: 1.1.0 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` diff --git a/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 b/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 index 03adf6c3b..c024b71b1 100644 --- a/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerDatabaseMail' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 index 7c1350292..1800e7be8 100644 --- a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerEndpoint' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 index 9c866b203..c22755497 100644 --- a/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerEndpointPermission' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 index b5bba8c29..3acca8f75 100644 --- a/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerEndpointState' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 index 99c711671..ba18141b5 100644 --- a/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 @@ -8,8 +8,6 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] # Suppressing this rule because PlainText is required for one of the functions used in this test [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() @@ -17,6 +15,12 @@ param() $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerLogin' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 @@ -386,9 +390,9 @@ try $mockTestTargetResourceParameters.Add('Disabled', $true) $mockTestTargetResourceParameters.Add('LoginType', 'SqlLogin') $mockTestTargetResourceParameters.Add('LoginCredential', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockSqlLoginPassword))) - + # Override mock declaration - Mock -CommandName Connect-SQL -MockWith {throw $mockAccountDisabledException} + Mock -CommandName Connect-SQL -MockWith {throw $mockAccountDisabledException} # Override Get-TargetResource Mock -CommandName Get-TargetResource {return New-Object PSObject -Property @{ @@ -403,7 +407,7 @@ try LoginPasswordExpirationEnabled = $true } } - + # Call the test target $result = Test-TargetResource @mockTestTargetResourceParameters @@ -420,9 +424,9 @@ try $mockTestTargetResourceParameters.Add('Disabled', $true) $mockTestTargetResourceParameters.Add('LoginType', 'SqlLogin') $mockTestTargetResourceParameters.Add('LoginCredential', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockSqlLoginPassword))) - + # Override mock declaration - Mock -CommandName Connect-SQL -MockWith {throw $mockLoginFailedException} + Mock -CommandName Connect-SQL -MockWith {throw $mockLoginFailedException} # Override Get-TargetResource Mock -CommandName Get-TargetResource {return New-Object PSObject -Property @{ @@ -437,7 +441,7 @@ try LoginPasswordExpirationEnabled = $true } } - + # Call the test target $result = Test-TargetResource @mockTestTargetResourceParameters @@ -447,16 +451,16 @@ try # Should be true $result | Should -Be $false } - + It 'Should throw exception when unkown error occurred and account is disabled' { $mockTestTargetResourceParameters = $getTargetResource_KnownSqlLogin.Clone() $mockTestTargetResourceParameters.Add('Ensure', 'Present') $mockTestTargetResourceParameters.Add('Disabled', $true) $mockTestTargetResourceParameters.Add('LoginType', 'SqlLogin') $mockTestTargetResourceParameters.Add('LoginCredential', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockSqlLoginPassword))) - + # Override mock declaration - Mock -CommandName Connect-SQL -MockWith {throw $mockException} + Mock -CommandName Connect-SQL -MockWith {throw $mockException} # Override Get-TargetResource Mock -CommandName Get-TargetResource {return New-Object PSObject -Property @{ @@ -471,13 +475,13 @@ try LoginPasswordExpirationEnabled = $true } } - + # Call the test target { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw Assert-MockCalled -CommandName Get-TargetResource -Scope It -Times 1 -Exactly Assert-MockCAlled -CommandName Connect-SQL -Scope It -Times 1 -Exactly - } + } } Context 'When the desired state is Present' { diff --git a/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 b/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 index eeaac7bda..7792db505 100644 --- a/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerMaxDop' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 b/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 index cebaee00b..9d0df2655 100644 --- a/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerMemory' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 b/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 index 1f39d5bf2..673477f6b 100644 --- a/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerNetwork' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 index e17ef628d..48ffbabe0 100644 --- a/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerPermission' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 index 742259445..dc092994b 100644 --- a/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 @@ -9,14 +9,18 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param() $script:DSCModuleName = 'SqlServerDSC' $script:DSCResourceName = 'MSFT_SqlServerReplication' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.1.0 [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) diff --git a/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 b/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 index 7fece5089..16d3bbd2a 100644 --- a/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerRole' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServerSecureConnection.Tests.ps1 b/Tests/Unit/MSFT_SqlServerSecureConnection.Tests.ps1 index 6e190a498..89ec8b503 100644 --- a/Tests/Unit/MSFT_SqlServerSecureConnection.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerSecureConnection.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServerSecureConnection' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 b/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 index 5fc8b2dd0..13adb1da7 100644 --- a/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlServiceAccount' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.1 @@ -177,7 +179,7 @@ try $managedComputerObject = New-Object -TypeName PSObject -Property @{ Name = $mockDefaultInstanceName ServiceAccount = $mockManagedServiceAccountName - Type = 'SqlServer' + Type = 'SqlServer' } $managedComputerObject | Add-Member @mockAddMemberParameters_SetServiceAccount @@ -498,7 +500,7 @@ try ) # Get the service name - Get-SqlServiceName -InstanceName $mockDefaultInstanceName -ServiceType $ServiceType | Should -Be $ExpectedServiceName + Get-SqlServiceName -InstanceName $mockDefaultInstanceName -ServiceType $ServiceType | Should -Be $ExpectedServiceName # Ensure the mock is utilized Assert-MockCalled -CommandName Get-ChildItem -ParameterFilter $mockGetChildItem_ParameterFilter -Scope It -Exactly -Times 1 @@ -806,7 +808,7 @@ try ServerName = $mockSqlServer InstanceName = $mockDefaultInstanceName ServiceType = $mockServiceType - ServiceAccount = $mockManagedServiceAccountCredential + ServiceAccount = $mockManagedServiceAccountCredential } It 'Should have the Managed Service Account' { diff --git a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 index 8383d2051..caeda7514 100644 --- a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 @@ -8,8 +8,6 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] # Suppressing this rule because PlainText is required for one of the functions used in this test [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() @@ -17,6 +15,12 @@ param() $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlSetup' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.0 diff --git a/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 index 46f2f0e6a..4474b7457 100644 --- a/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 @@ -8,13 +8,15 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() - $script:DSCModuleName = 'SqlServerDsc' $script:DSCResourceName = 'MSFT_SqlWaitForAG' +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} + #region HEADER # Unit Test Template Version: 1.2.1 diff --git a/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 index dcf7c023d..291f6c974 100644 --- a/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 @@ -8,9 +8,14 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container2', ContainerImage = 'microsoft/windowsservercore')] -param() +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlWindowsFirewall' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:DSCResourceName) -Verbose + return +} #region HEADER diff --git a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 index 2ab8817f1..e314a6855 100644 --- a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 +++ b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 @@ -8,15 +8,19 @@ https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#bootstrap-script-assert-testenvironment #> -# This is used to make sure the unit test run in a container. -[Microsoft.DscResourceKit.UnitTest(ContainerName = 'Container1', ContainerImage = 'microsoft/windowsservercore')] # To run these tests, we have to fake login credentials [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () # Unit Test Template Version: 1.1.0 -$script:moduleName = 'SqlServerDscHelper' +$script:helperModuleName = 'SqlServerDscHelper' + +if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') +{ + Write-Verbose -Message ('Unit test for {0} will be skipped unless $env:CONFIGURATION is set to ''Unit''.' -f $script:helperModuleName) -Verbose + return +} [System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` @@ -35,7 +39,7 @@ Add-Type -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Pa Import-Module -Name (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests') -ChildPath 'Unit') -ChildPath 'Stubs') -ChildPath 'SQLPSStub.psm1') -Global -Force # Begin Testing -InModuleScope $script:moduleName { +InModuleScope $script:helperModuleName { $mockNewObject_MicrosoftAnalysisServicesServer = { return New-Object -TypeName Object | Add-Member -MemberType ScriptMethod -Name Connect -Value { @@ -154,7 +158,7 @@ InModuleScope $script:moduleName { $mockInnerException | Add-Member -Name 'Number' -Value 2 -MemberType NoteProperty $mockException = New-Object System.Exception "This is a mock exception object", $mockInnerException $mockException | Add-Member -Name 'Number' -Value 1 -MemberType NoteProperty - + Describe 'Testing Restart-SqlService' { Context 'Restart-SqlService standalone instance' { @@ -2047,7 +2051,7 @@ InModuleScope $script:moduleName { Context 'When getting service account' { It 'Should return NT AUTHORITY\SYSTEM' { $returnValue = Get-ServiceAccount -ServiceAccount $mockLocalSystemAccountCredential - + $returnValue.UserName | Should -Be $mockLocalSystemAccountUserName $returnValue.Password | Should -BeNullOrEmpty } @@ -2076,7 +2080,7 @@ InModuleScope $script:moduleName { Describe 'Testing Find-ExceptionByNumber'{ Context 'When searching Exception objects'{ - It 'Should return true for main exception' { + It 'Should return true for main exception' { Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 1 | Should -Be $true } diff --git a/appveyor.yml b/appveyor.yml index d890750f8..9873f9d72 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,9 @@ #---------------------------------# version: 9.0.{build}.0 image: Visual Studio 2017 +configuration: + - Unit + - Integration install: - git clone https://github.com/PowerShell/DscResource.Tests - ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose From ea50b39622b90bf44e28a10f47f8a6a2bc018576 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 13:59:46 +0100 Subject: [PATCH 12/18] Add build matrix to skip code coverage during integration testing --- appveyor.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 9873f9d72..5d54cb63e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,7 +22,22 @@ build: false # test configuration # #---------------------------------# -test_script: +for: +- + matrix: + only: + - configuration: Integration + + test_script: + - ps: | + Invoke-AppveyorTestScriptTask -ExcludeTag @() -RunTestInOrder + +- + matrix: + only: + - configuration: Unit + + test_script: - ps: | # Workaround for issue #239 and issue #774. Write-Verbose -Message '--- WORKAROUND FOR ISSUE #239 AND ISSUE #774 ---' -Verbose From 90809351fc9fff200f166d5e25dc97c4b06779d5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 14:00:03 +0100 Subject: [PATCH 13/18] Add workaround to integration test --- appveyor.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5d54cb63e..3fcec3415 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,6 +30,17 @@ for: test_script: - ps: | + # Workaround for issue #798 + Write-Verbose -Message '--- WORKAROUND FOR ISSUE #798 ---' -Verbose + $azureModules = Get-Module -ListAvailable -Name 'Azure*' + $azureUniqueModulePath = Split-Path -Path (Split-Path $azureModules.Path -Parent) -Parent | Sort-Object -Unique + $azureUniqueModulePath | ForEach-Object -Process { + $newFolderName = '{0}.old' -f (Split-Path -Path $_ -Leaf) + Write-Verbose ('Renaming ''{0}'' to ''..\{1}''' -f $_, $newFolderName) -Verbose + Rename-Item $_ -NewName $newFolderName -Force + } + Write-Verbose -Message '' -Verbose + Invoke-AppveyorTestScriptTask -ExcludeTag @() -RunTestInOrder - @@ -48,18 +59,6 @@ for: Write-Verbose ('Renaming ''{0}'' to ''..\{1}''' -f $_, $newFolderName) -Verbose Rename-Item $_ -NewName $newFolderName -Force } - - Write-Verbose -Message '' -Verbose - - # Workaround for issue #798 - Write-Verbose -Message '--- WORKAROUND FOR ISSUE #798 ---' -Verbose - $azureModules = Get-Module -ListAvailable -Name 'Azure*' - $azureUniqueModulePath = Split-Path -Path (Split-Path $azureModules.Path -Parent) -Parent | Sort-Object -Unique - $azureUniqueModulePath | ForEach-Object -Process { - $newFolderName = '{0}.old' -f (Split-Path -Path $_ -Leaf) - Write-Verbose ('Renaming ''{0}'' to ''..\{1}''' -f $_, $newFolderName) -Verbose - Rename-Item $_ -NewName $newFolderName -Force - } Write-Verbose -Message '' -Verbose Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag @() -RunTestInOrder From c57b6625a7fdf44a8bf6578d86b6c51b785308be Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 14:45:23 +0100 Subject: [PATCH 14/18] Limit the modules affected by the workaround for issue 798 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 3fcec3415..365cf22fa 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,7 +32,7 @@ for: - ps: | # Workaround for issue #798 Write-Verbose -Message '--- WORKAROUND FOR ISSUE #798 ---' -Verbose - $azureModules = Get-Module -ListAvailable -Name 'Azure*' + $azureModules = Get-Module -ListAvailable -Name 'Azure*' | Where-Object -FilterScript { $_.Name -notlike 'AzureRm*' } $azureUniqueModulePath = Split-Path -Path (Split-Path $azureModules.Path -Parent) -Parent | Sort-Object -Unique $azureUniqueModulePath | ForEach-Object -Process { $newFolderName = '{0}.old' -f (Split-Path -Path $_ -Leaf) From eb2b84dc4ff56efc68a7e1b7fa99571e225fa8d1 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 15:07:32 +0100 Subject: [PATCH 15/18] Add workaround for issue 239 and 774 to integration tests worker --- appveyor.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 365cf22fa..52a777af9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,6 +30,15 @@ for: test_script: - ps: | + Write-Verbose -Message '--- WORKAROUND FOR ISSUE #239 AND ISSUE #774 ---' -Verbose + $sqlModules = Get-Module -ListAvailable -Name 'sql*' + $sqlUniqueModulePath = Split-Path -Path (Split-Path $sqlModules.Path -Parent) -Parent | Sort-Object -Unique + $sqlUniqueModulePath | ForEach-Object -Process { + $newFolderName = '{0}.old' -f (Split-Path -Path $_ -Leaf) + Write-Verbose ('Renaming ''{0}'' to ''..\{1}''' -f $_, $newFolderName) -Verbose + Rename-Item $_ -NewName $newFolderName -Force + } + Write-Verbose -Message '' -Verbose # Workaround for issue #798 Write-Verbose -Message '--- WORKAROUND FOR ISSUE #798 ---' -Verbose $azureModules = Get-Module -ListAvailable -Name 'Azure*' | Where-Object -FilterScript { $_.Name -notlike 'AzureRm*' } From 4a810adcec2d53c06a2f98dea3cd9a506f2458b5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 16:39:41 +0100 Subject: [PATCH 16/18] Changes to SqlServerDsc - Clean up error handling in some of the integration tests that was part of a workaround for a bug in Pester. The bug is resolved, and the error handling is not again built into Pester. --- CHANGELOG.md | 12 + ...T_SqlAlwaysOnService.Integration.Tests.ps1 | 42 +- .../MSFT_SqlRS.Integration.Tests.ps1 | 51 +- ...FT_SqlServiceAccount.Integration.Tests.ps1 | 101 +--- Tests/Unit/CommonResourceHelper.Tests.ps1 | 6 +- Tests/Unit/MSFT_SqlAG.Tests.ps1 | 12 +- Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 | 489 +++++++++--------- Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 | 6 +- Tests/Unit/MSFT_SqlAlias.Tests.ps1 | 6 +- .../MSFT_SqlDatabaseDefaultLocation.Tests.ps1 | 6 +- .../MSFT_SqlDatabaseRecoveryModel.Tests.ps1 | 1 + Tests/Unit/MSFT_SqlScript.Tests.ps1 | 6 +- Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 | 6 +- Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 | 6 +- Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 | 6 +- Tests/Unit/SqlServerDSCHelper.Tests.ps1 | 2 +- 16 files changed, 309 insertions(+), 449 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 466c115d3..f9b9210dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ [issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260) in the previous release, as it only mitigated the issue, it did not solve the issue. + - Removed the container testing since that broke the integration tests, + possible due to using excessive amount of memory on the AppVeyor build + worker. This will make the unit tests to take a bit longer to run. + ([issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260)). + - The unit tests and the integration tests are now run in two separate + build workers in AppVeyor. One build worker runs the integration tests, + while a second build worker runs the unit tests. The build workers runs + in parallel on paid accounts, but sequentially on free accounts. + ([issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260)). + - Clean up error handling in some of the integration tests that was + part of a workaround for a bug in Pester. The bug is resolved, and + the error handling is not again built into Pester. - Changes to SqlServiceAccount - Fixed Get-ServiceObject when searching for Integration Services service. Unlike the rest of SQL Server services, the Integration Services service diff --git a/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 index cfc8ecb53..90cd6fae5 100644 --- a/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 @@ -35,8 +35,6 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion -$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:' - $testRootFolderPath = Split-Path -Path $PSScriptRoot -Parent Import-Module -Name (Join-Path -Path $testRootFolderPath -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'CommonTestHelper.psm1')) -Force @@ -88,15 +86,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -124,15 +114,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -176,15 +158,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -227,15 +201,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $script:integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } diff --git a/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 index 38a0b7f5e..3c2ed2da7 100644 --- a/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 @@ -33,7 +33,6 @@ $TestEnvironment = Initialize-TestEnvironment ` -DSCResourceName $script:DSCResourceName ` -TestType Integration -$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:' #endregion $mockSqlInstallAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -82,15 +81,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -118,15 +109,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -218,15 +201,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -282,15 +257,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -355,15 +322,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } diff --git a/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 index 5adaa576a..3daacb144 100644 --- a/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlServiceAccount.Integration.Tests.ps1 @@ -33,7 +33,6 @@ $TestEnvironment = Initialize-TestEnvironment ` -DSCResourceName $script:DSCResourceName ` -TestType Integration -$script:integrationErrorMessagePrefix = 'INTEGRATION ERROR MESSAGE:' #endregion $mockSqlInstallAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -98,15 +97,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -134,15 +125,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -188,15 +171,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -241,15 +216,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -295,15 +262,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -347,15 +306,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } } @@ -383,15 +334,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -437,15 +380,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -490,15 +425,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } @@ -544,15 +471,7 @@ try ErrorAction = 'Stop' } - try - { - Start-DscConfiguration @startDscConfigurationParameters - } - catch - { - Write-Verbose -Message ('{0} {1}' -f $integrationErrorMessagePrefix, $_) -Verbose - throw $_ - } + Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } diff --git a/Tests/Unit/CommonResourceHelper.Tests.ps1 b/Tests/Unit/CommonResourceHelper.Tests.ps1 index 643ecfa08..85250a0e1 100644 --- a/Tests/Unit/CommonResourceHelper.Tests.ps1 +++ b/Tests/Unit/CommonResourceHelper.Tests.ps1 @@ -17,17 +17,17 @@ if ($env:APPVEYOR -eq $true -and $env:CONFIGURATION -ne 'Unit') return } -Describe 'CommonResourceHelper Unit Tests' { +Describe "$script:helperModuleName Unit Tests" { BeforeAll { # Import the CommonResourceHelper module to test $dscResourcesFolderFilePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) ` -ChildPath 'DscResources' Import-Module -Name (Join-Path -Path $dscResourcesFolderFilePath ` - -ChildPath 'CommonResourceHelper.psm1') -Force + -ChildPath "$script:helperModuleName.psm1") -Force } - InModuleScope 'CommonResourceHelper' { + InModuleScope $script:helperModuleName { Describe 'Get-LocalizedData' { $mockTestPath = { return $mockTestPathReturnValue diff --git a/Tests/Unit/MSFT_SqlAG.Tests.ps1 b/Tests/Unit/MSFT_SqlAG.Tests.ps1 index f096adac4..80dc09634 100644 --- a/Tests/Unit/MSFT_SqlAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAG.Tests.ps1 @@ -31,13 +31,14 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'CommonTestHelper.psm1'))) -Force -Global $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlAG' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Load the SMO stubs Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) @@ -45,7 +46,8 @@ function Invoke-TestSetup { Import-SQLModuleStub } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -54,7 +56,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlAG' { + InModuleScope $script:DSCResourceName { #region parameter mocks diff --git a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 index 2a6582f76..cf06947f9 100644 --- a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 @@ -35,17 +35,18 @@ Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlAGDatabase' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER -function Invoke-TestSetup { - +function Invoke-TestSetup +{ } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment # TODO: Other Optional Cleanup Code Goes Here... @@ -56,320 +57,320 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlAGDatabase' { + InModuleScope $script:DSCResourceName { #region Parameter Mocks - # The databases defined in the resource - $mockDatabaseNameParameter = @( - 'DB*' - 'AnotherDB' - '3rd*OfDatabase' - '4th*OfDatabase' - ) + # The databases defined in the resource + $mockDatabaseNameParameter = @( + 'DB*' + 'AnotherDB' + '3rd*OfDatabase' + '4th*OfDatabase' + ) - $mockDatabaseNameParameterWithNonExistingDatabases = @( - 'NotFound*' - 'Unknown1' - ) + $mockDatabaseNameParameterWithNonExistingDatabases = @( + 'NotFound*' + 'Unknown1' + ) - $mockBackupPath = 'X:\Backup' + $mockBackupPath = 'X:\Backup' - $mockProcessOnlyOnActiveNode = $false + $mockProcessOnlyOnActiveNode = $false #endregion Parameter Mocks #region mock names - $mockServerObjectDomainInstanceName = 'Server1' - $mockPrimaryServerObjectDomainInstanceName = 'Server2' - $mockAvailabilityGroupObjectName = 'AvailabilityGroup1' - $mockAvailabilityGroupWithoutDatabasesObjectName = 'AvailabilityGroupWithoutDatabases' - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName = 'AvailabilityGroup2' + $mockServerObjectDomainInstanceName = 'Server1' + $mockPrimaryServerObjectDomainInstanceName = 'Server2' + $mockAvailabilityGroupObjectName = 'AvailabilityGroup1' + $mockAvailabilityGroupWithoutDatabasesObjectName = 'AvailabilityGroupWithoutDatabases' + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName = 'AvailabilityGroup2' #endregion mock names #region Availability Replica Mocks - $mockAvailabilityReplicaObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityReplicaCollection - foreach ( $mockAvailabilityReplicaName in @('Server1','Server2') ) - { - $newAvailabilityReplicaObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityReplica - $newAvailabilityReplicaObject.Name = $mockAvailabilityReplicaName - - if ( $mockServerObjectDomainInstanceName -eq $mockAvailabilityReplicaName ) - { - $newAvailabilityReplicaObject.Role = 'Primary' - } + $mockAvailabilityReplicaObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityReplicaCollection + foreach ( $mockAvailabilityReplicaName in @('Server1','Server2') ) + { + $newAvailabilityReplicaObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityReplica + $newAvailabilityReplicaObject.Name = $mockAvailabilityReplicaName - $mockAvailabilityReplicaObjects.Add($newAvailabilityReplicaObject) + if ( $mockServerObjectDomainInstanceName -eq $mockAvailabilityReplicaName ) + { + $newAvailabilityReplicaObject.Role = 'Primary' } + $mockAvailabilityReplicaObjects.Add($newAvailabilityReplicaObject) + } + #endregion Availability Replica Mocks #region Availability Group Mocks - $mockAvailabilityDatabaseNames = @( - 'DB2' - '3rdTypeOfDatabase' - 'UndefinedDatabase' - ) - - $mockAvailabilityDatabaseAbsentResults = @( - 'DB2' - '3rdTypeOfDatabase' - ) - - $mockAvailabilityDatabaseExactlyAddResults = @( - 'DB1' - ) - - $mockAvailabilityDatabaseExactlyRemoveResults = @( - 'UndefinedDatabase' - ) - - $mockAvailabilityDatabasePresentResults = @( - 'DB1' - ) - - $mockAvailabilityDatabaseObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityDatabaseCollection - foreach ( $mockAvailabilityDatabaseName in $mockAvailabilityDatabaseNames ) - { - $newAvailabilityDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityDatabase - $newAvailabilityDatabaseObject.Name = $mockAvailabilityDatabaseName - $mockAvailabilityDatabaseObjects.Add($newAvailabilityDatabaseObject) - } + $mockAvailabilityDatabaseNames = @( + 'DB2' + '3rdTypeOfDatabase' + 'UndefinedDatabase' + ) + + $mockAvailabilityDatabaseAbsentResults = @( + 'DB2' + '3rdTypeOfDatabase' + ) + + $mockAvailabilityDatabaseExactlyAddResults = @( + 'DB1' + ) + + $mockAvailabilityDatabaseExactlyRemoveResults = @( + 'UndefinedDatabase' + ) + + $mockAvailabilityDatabasePresentResults = @( + 'DB1' + ) + + $mockAvailabilityDatabaseObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityDatabaseCollection + foreach ( $mockAvailabilityDatabaseName in $mockAvailabilityDatabaseNames ) + { + $newAvailabilityDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityDatabase + $newAvailabilityDatabaseObject.Name = $mockAvailabilityDatabaseName + $mockAvailabilityDatabaseObjects.Add($newAvailabilityDatabaseObject) + } - $mockBadAvailabilityGroupObject = New-Object -TypeName Object + $mockBadAvailabilityGroupObject = New-Object -TypeName Object - $mockAvailabilityGroupObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup - $mockAvailabilityGroupObject.AvailabilityDatabases = $mockAvailabilityDatabaseObjects - $mockAvailabilityGroupObject.Name = $mockAvailabilityGroupObjectName - $mockAvailabilityGroupObject.PrimaryReplicaServerName = $mockServerObjectDomainInstanceName - $mockAvailabilityGroupObject.AvailabilityReplicas = $mockAvailabilityReplicaObjects + $mockAvailabilityGroupObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup + $mockAvailabilityGroupObject.AvailabilityDatabases = $mockAvailabilityDatabaseObjects + $mockAvailabilityGroupObject.Name = $mockAvailabilityGroupObjectName + $mockAvailabilityGroupObject.PrimaryReplicaServerName = $mockServerObjectDomainInstanceName + $mockAvailabilityGroupObject.AvailabilityReplicas = $mockAvailabilityReplicaObjects - $mockAvailabilityGroupWithoutDatabasesObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup - $mockAvailabilityGroupWithoutDatabasesObject.Name = $mockAvailabilityGroupWithoutDatabasesObjectName - $mockAvailabilityGroupWithoutDatabasesObject.PrimaryReplicaServerName = $mockServerObjectDomainInstanceName - $mockAvailabilityGroupWithoutDatabasesObject.AvailabilityReplicas = $mockAvailabilityReplicaObjects + $mockAvailabilityGroupWithoutDatabasesObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup + $mockAvailabilityGroupWithoutDatabasesObject.Name = $mockAvailabilityGroupWithoutDatabasesObjectName + $mockAvailabilityGroupWithoutDatabasesObject.PrimaryReplicaServerName = $mockServerObjectDomainInstanceName + $mockAvailabilityGroupWithoutDatabasesObject.AvailabilityReplicas = $mockAvailabilityReplicaObjects - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.AvailabilityDatabases = $mockAvailabilityDatabaseObjects - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.PrimaryReplicaServerName = $mockPrimaryServerObjectDomainInstanceName - $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.AvailabilityReplicas = $mockAvailabilityReplicaObjects + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroup + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.AvailabilityDatabases = $mockAvailabilityDatabaseObjects + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.PrimaryReplicaServerName = $mockPrimaryServerObjectDomainInstanceName + $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.AvailabilityReplicas = $mockAvailabilityReplicaObjects #endregion Availability Group Mocks #region Certificate Mocks - [byte[]]$mockThumbprint1 = @( - 83 - 121 - 115 - 116 - 101 - 109 - 46 - 84 - 101 - 120 - 116 - 46 - 85 - 84 - 70 - 56 - 69 - 110 - 99 - 111 - 100 - 105 - 110 - 103 - ) - - [byte[]]$mockThumbprint2 = @( - 83 - 121 - 115 - 23 - 101 - 109 - 46 - 84 - 101 - 120 - 116 - 85 - 85 - 84 - 70 - 56 - 69 - 23 - 99 - 111 - 100 - 105 - 110 - 103 - ) - - $mockCertificateObject1 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Certificate - $mockCertificateObject1.Thumbprint = $mockThumbprint1 - - $mockCertificateObject2 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Certificate - $mockCertificateObject2.Thumbprint = $mockThumbprint2 - - $mockDatabaseEncryptionKeyObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseEncryptionKey - $mockDatabaseEncryptionKeyObject.EncryptorName = 'TDE Cert' - $mockDatabaseEncryptionKeyObject.Thumbprint = $mockThumbprint1 + [byte[]]$mockThumbprint1 = @( + 83 + 121 + 115 + 116 + 101 + 109 + 46 + 84 + 101 + 120 + 116 + 46 + 85 + 84 + 70 + 56 + 69 + 110 + 99 + 111 + 100 + 105 + 110 + 103 + ) + + [byte[]]$mockThumbprint2 = @( + 83 + 121 + 115 + 23 + 101 + 109 + 46 + 84 + 101 + 120 + 116 + 85 + 85 + 84 + 70 + 56 + 69 + 23 + 99 + 111 + 100 + 105 + 110 + 103 + ) + + $mockCertificateObject1 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Certificate + $mockCertificateObject1.Thumbprint = $mockThumbprint1 + + $mockCertificateObject2 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Certificate + $mockCertificateObject2.Thumbprint = $mockThumbprint2 + + $mockDatabaseEncryptionKeyObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseEncryptionKey + $mockDatabaseEncryptionKeyObject.EncryptorName = 'TDE Cert' + $mockDatabaseEncryptionKeyObject.Thumbprint = $mockThumbprint1 #endregion Certificate Mocks #region Database File Mocks - $mockDataFilePath = 'E:\SqlData' - $mockLogFilePath = 'F:\SqlLog' - $mockDataFilePathIncorrect = 'G:\SqlData' - $mockLogFilePathIncorrect = 'H:\SqlData' + $mockDataFilePath = 'E:\SqlData' + $mockLogFilePath = 'F:\SqlLog' + $mockDataFilePathIncorrect = 'G:\SqlData' + $mockLogFilePathIncorrect = 'H:\SqlData' #endregion Database File Mocks #region Database Mocks - # The databases found on the instance - $mockPresentDatabaseNames = @( - 'DB1' - 'DB2' - '3rdTypeOfDatabase' - 'UndefinedDatabase' - ) - - $mockMasterDatabaseName = 'master' - $mockMasterDatabaseObject1 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database - $mockMasterDatabaseObject1.Name = $mockMasterDatabaseName - $mockMasterDatabaseObject1.ID = 1 - $mockMasterDatabaseObject1.Certificates = @($mockCertificateObject1) - $mockMasterDatabaseObject1.FileGroups = @{ + # The databases found on the instance + $mockPresentDatabaseNames = @( + 'DB1' + 'DB2' + '3rdTypeOfDatabase' + 'UndefinedDatabase' + ) + + $mockMasterDatabaseName = 'master' + $mockMasterDatabaseObject1 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database + $mockMasterDatabaseObject1.Name = $mockMasterDatabaseName + $mockMasterDatabaseObject1.ID = 1 + $mockMasterDatabaseObject1.Certificates = @($mockCertificateObject1) + $mockMasterDatabaseObject1.FileGroups = @{ + Name = 'PRIMARY' + Files = @{ + FileName = ( [IO.Path]::Combine( $mockDataFilePath, "$($mockMasterDatabaseName).mdf" ) ) + } + } + $mockMasterDatabaseObject1.LogFiles = @{ + FileName = ( [IO.Path]::Combine( $mockLogFilePath, "$($mockMasterDatabaseName).ldf" ) ) + } + + $mockDatabaseObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseCollection + foreach ( $mockPresentDatabaseName in $mockPresentDatabaseNames ) + { + $newDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database + $newDatabaseObject.Name = $mockPresentDatabaseName + $newDatabaseObject.FileGroups = @{ Name = 'PRIMARY' Files = @{ - FileName = ( [IO.Path]::Combine( $mockDataFilePath, "$($mockMasterDatabaseName).mdf" ) ) + FileName = ( [IO.Path]::Combine( $mockDataFilePath, "$($mockPresentDatabaseName).mdf" ) ) } } - $mockMasterDatabaseObject1.LogFiles = @{ - FileName = ( [IO.Path]::Combine( $mockLogFilePath, "$($mockMasterDatabaseName).ldf" ) ) + $newDatabaseObject.LogFiles = @{ + FileName = ( [IO.Path]::Combine( $mockLogFilePath, "$($mockPresentDatabaseName).ldf" ) ) } - $mockDatabaseObjects = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseCollection - foreach ( $mockPresentDatabaseName in $mockPresentDatabaseNames ) - { - $newDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database - $newDatabaseObject.Name = $mockPresentDatabaseName - $newDatabaseObject.FileGroups = @{ - Name = 'PRIMARY' - Files = @{ - FileName = ( [IO.Path]::Combine( $mockDataFilePath, "$($mockPresentDatabaseName).mdf" ) ) - } - } - $newDatabaseObject.LogFiles = @{ - FileName = ( [IO.Path]::Combine( $mockLogFilePath, "$($mockPresentDatabaseName).ldf" ) ) + # Add the database object to the database collection + $mockDatabaseObjects.Add($newDatabaseObject) + } + $mockDatabaseObjects.Add($mockMasterDatabaseObject1) + + $mockDatabaseObjectsWithIncorrectFileNames = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseCollection + foreach ( $mockPresentDatabaseName in $mockPresentDatabaseNames ) + { + $newDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database + $newDatabaseObject.Name = $mockPresentDatabaseName + $newDatabaseObject.FileGroups = @{ + Name = 'PRIMARY' + Files = @{ + FileName = ( [IO.Path]::Combine( $mockDataFilePathIncorrect, "$($mockPresentDatabaseName).mdf" ) ) } - - # Add the database object to the database collection - $mockDatabaseObjects.Add($newDatabaseObject) } - $mockDatabaseObjects.Add($mockMasterDatabaseObject1) - - $mockDatabaseObjectsWithIncorrectFileNames = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabaseCollection - foreach ( $mockPresentDatabaseName in $mockPresentDatabaseNames ) - { - $newDatabaseObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database - $newDatabaseObject.Name = $mockPresentDatabaseName - $newDatabaseObject.FileGroups = @{ - Name = 'PRIMARY' - Files = @{ - FileName = ( [IO.Path]::Combine( $mockDataFilePathIncorrect, "$($mockPresentDatabaseName).mdf" ) ) - } - } - $newDatabaseObject.LogFiles = @{ - FileName = ( [IO.Path]::Combine( $mockLogFilePathIncorrect, "$($mockPresentDatabaseName).ldf" ) ) - } - - # Add the database object to the database collection - $mockDatabaseObjectsWithIncorrectFileNames.Add($newDatabaseObject) + $newDatabaseObject.LogFiles = @{ + FileName = ( [IO.Path]::Combine( $mockLogFilePathIncorrect, "$($mockPresentDatabaseName).ldf" ) ) } + # Add the database object to the database collection + $mockDatabaseObjectsWithIncorrectFileNames.Add($newDatabaseObject) + } + #endregion Database Mocks #region Server mocks - $mockBadServerObject = New-Object -TypeName Object - - $mockServerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server - $mockServerObject.AvailabilityGroups = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroupCollection - $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupObject.Clone()) - $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupWithoutDatabasesObject.Clone()) - $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Clone()) - $mockServerObject.Databases = $mockDatabaseObjects - $mockServerObject.DomainInstanceName = $mockServerObjectDomainInstanceName - $mockServerObject.NetName = $mockServerObjectDomainInstanceName - $mockServerObject.ServiceName = 'MSSQLSERVER' - $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupObject.Name].LocalReplicaRole = 'Primary' - $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupWithoutDatabasesObject.Name].LocalReplicaRole = 'Primary' - $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name].LocalReplicaRole = 'Secondary' - - $mockServer2Object = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server - $mockServer2Object.AvailabilityGroups = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroupCollection - $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupObject.Clone()) - $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupWithoutDatabasesObject.Clone()) - $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Clone()) - $mockServer2Object.Databases = $mockDatabaseObjects - $mockServer2Object.DomainInstanceName = $mockPrimaryServerObjectDomainInstanceName - $mockServer2Object.NetName = $mockPrimaryServerObjectDomainInstanceName - $mockServer2Object.ServiceName = 'MSSQLSERVER' - $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupObject.Name].LocalReplicaRole = 'Secondary' - $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupWithoutDatabasesObject.Name].LocalReplicaRole = 'Secondary' - $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name].LocalReplicaRole = 'Primary' + $mockBadServerObject = New-Object -TypeName Object + + $mockServerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server + $mockServerObject.AvailabilityGroups = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroupCollection + $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupObject.Clone()) + $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupWithoutDatabasesObject.Clone()) + $mockServerObject.AvailabilityGroups.Add($mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Clone()) + $mockServerObject.Databases = $mockDatabaseObjects + $mockServerObject.DomainInstanceName = $mockServerObjectDomainInstanceName + $mockServerObject.NetName = $mockServerObjectDomainInstanceName + $mockServerObject.ServiceName = 'MSSQLSERVER' + $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupObject.Name].LocalReplicaRole = 'Primary' + $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupWithoutDatabasesObject.Name].LocalReplicaRole = 'Primary' + $mockServerObject.AvailabilityGroups[$mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name].LocalReplicaRole = 'Secondary' + + $mockServer2Object = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server + $mockServer2Object.AvailabilityGroups = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityGroupCollection + $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupObject.Clone()) + $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupWithoutDatabasesObject.Clone()) + $mockServer2Object.AvailabilityGroups.Add($mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Clone()) + $mockServer2Object.Databases = $mockDatabaseObjects + $mockServer2Object.DomainInstanceName = $mockPrimaryServerObjectDomainInstanceName + $mockServer2Object.NetName = $mockPrimaryServerObjectDomainInstanceName + $mockServer2Object.ServiceName = 'MSSQLSERVER' + $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupObject.Name].LocalReplicaRole = 'Secondary' + $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupWithoutDatabasesObject.Name].LocalReplicaRole = 'Secondary' + $mockServer2Object.AvailabilityGroups[$mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name].LocalReplicaRole = 'Primary' #endregion Server mocks #region Invoke Query Mock - $mockResultInvokeQueryFileExist = { - return @{ - Tables = @{ - Rows = @{ - 'File is a Directory' = 1 - } + $mockResultInvokeQueryFileExist = { + return @{ + Tables = @{ + Rows = @{ + 'File is a Directory' = 1 } } } + } - $mockResultInvokeQueryFileNotExist = { - return @{ - Tables = @{ - Rows = @{ - 'File is a Directory' = 0 - } + $mockResultInvokeQueryFileNotExist = { + return @{ + Tables = @{ + Rows = @{ + 'File is a Directory' = 0 } } } + } - $mockInvokeQueryParameterRestoreDatabase = { - $Query -like 'RESTORE DATABASE * + $mockInvokeQueryParameterRestoreDatabase = { + $Query -like 'RESTORE DATABASE * FROM DISK = * WITH NORECOVERY' - } + } - $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs = { - $Query -like 'EXECUTE AS LOGIN = * + $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs = { + $Query -like 'EXECUTE AS LOGIN = * RESTORE DATABASE * FROM DISK = * WITH NORECOVERY' - } + } #endregion Invoke Query Mock diff --git a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 index f514d81e7..1c50b53ed 100644 --- a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 @@ -33,8 +33,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlAGReplica' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -53,7 +53,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlAGReplica' { + InModuleScope $script:DSCResourceName { #region parameter mocks diff --git a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 index 788caf580..91631939a 100644 --- a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 @@ -30,8 +30,8 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlAlias' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -48,7 +48,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlAlias' { + InModuleScope $script:DSCResourceName { $registryPath = 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' $registryPathWow6432Node = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo' diff --git a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 index 67e656ee5..7c77a0543 100644 --- a/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 @@ -32,8 +32,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlDatabaseDefaultLocation' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -53,7 +53,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlDatabaseDefaultLocation' { + InModuleScope $script:DSCResourceName { $mockServerName = 'localhost' $mockInstanceName = 'MSSQLSERVER' $mockSQLDataPath = 'C:\Program Files\Data\' diff --git a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 index a912d1ce7..b69e33734 100644 --- a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 @@ -49,6 +49,7 @@ function Invoke-TestCleanup try { Invoke-TestSetup + InModuleScope $script:DSCResourceName { $mockServerName = 'localhost' $mockInstanceName = 'MSSQLSERVER' diff --git a/Tests/Unit/MSFT_SqlScript.Tests.ps1 b/Tests/Unit/MSFT_SqlScript.Tests.ps1 index 4cd199901..f6bb2193f 100644 --- a/Tests/Unit/MSFT_SqlScript.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScript.Tests.ps1 @@ -36,8 +36,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'SqlServerDsc $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlScript' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -57,7 +57,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlScript' { + InModuleScope $script:DSCResourceName { InModuleScope 'SqlServerDscHelper' { $script:DSCModuleName = 'SqlServerDsc' $resourceName = 'MSFT_SqlScript' diff --git a/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 b/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 index 1861e9669..fdc3e21aa 100644 --- a/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScriptQuery.Tests.ps1 @@ -35,8 +35,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource. Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'SqlServerDscHelper.psm1') $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlScriptQuery' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -56,7 +56,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlScriptQuery' { + InModuleScope $script:DSCResourceName { InModuleScope 'SqlServerDscHelper' { $script:DSCModuleName = 'SqlServerDsc' $resourceName = 'MSFT_SqlScriptQuery' diff --git a/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 index 4474b7457..8de046755 100644 --- a/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 @@ -30,8 +30,8 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlWaitForAG' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -48,7 +48,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlWaitForAG' { + InModuleScope $script:DSCResourceName { $mockClusterGroupName = 'AGTest' $mockRetryInterval = 1 $mockRetryCount = 2 diff --git a/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 index 291f6c974..3aa7c3505 100644 --- a/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 @@ -30,8 +30,8 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'SqlServerDsc' ` - -DSCResourceName 'MSFT_SqlWindowsFirewall' ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion HEADER @@ -48,7 +48,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_SqlWindowsFirewall' { + InModuleScope $script:DSCResourceName { <# Testing two major versions to verify Integration Services differences (i.e service name). No point in testing each supported SQL Server version, since there are no difference diff --git a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 index e314a6855..30decc1d3 100644 --- a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 +++ b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 @@ -30,7 +30,7 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -Import-Module (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath 'SqlServerDscHelper.psm1') -Scope Global -Force +Import-Module (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath "$script:helperModuleName.psm1") -Scope Global -Force # Loading mocked classes Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) From ea96b40c676bd98ab273734104488edd75032115 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 16:44:44 +0100 Subject: [PATCH 17/18] Remove commented code --- Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 9 --------- Tests/Integration/MSFT_SqlSetup.config.ps1 | 4 ---- 2 files changed, 13 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index 655683cbd..6e170142d 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -107,16 +107,12 @@ try $mockForceReboot = $ConfigurationData.AllNodes.ForceReboot $mockIsoMediaFilePath = $ConfigurationData.AllNodes.ImagePath $mockIsoMediaDriveLetter = $ConfigurationData.AllNodes.DriveLetter - #$mockServicePackMediaFilePath = $ConfigurationData.AllNodes.ImagePathServicePack $mockSourceMediaUrl = 'https://download.microsoft.com/download/9/0/7/907AD35F-9F9C-43A5-9789-52470555DB90/ENU/SQLServer2016SP1-FullSlipstream-x64-ENU.iso' - #$mockServicePackMediaUrl = 'https://download.microsoft.com/download/9/2/B/92BAD988-00C5-4F68-811E-B7FFBE009B00/SQLServer2016SP2-KB4052908-x64-ENU.exe' # Download SQL Server media if (-not (Test-Path -Path $mockIsoMediaFilePath)) { - # Create the Updates folder - #New-Item -ItemType Directory -Path (Split-Path -Path $mockServicePackMediaFilePath -Parent) -Force # By switching to 'SilentlyContinue' should theoretically increase the download speed. $previousProgressPreference = $ProgressPreference @@ -128,11 +124,6 @@ try Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath -Algorithm 'SHA384').Hash) -Verbose - #Write-Verbose -Message "Start downloading the SQL Server Service Pack media at $(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')" -Verbose - - #Invoke-WebRequest -Uri $mockServicePackMediaUrl -OutFile $mockServicePackMediaFilePath - #Write-Verbose -Message ('SQL Server Service Pack media file has hash ''{0}''' -f (Get-FileHash -Path $mockServicePackMediaFilePath -Algorithm SHA384).Hash) -Verbose - $ProgressPreference = $previousProgressPreference # Double check that the SQL media was downloaded. diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 121659f1a..141b3376b 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -38,7 +38,6 @@ $ConfigurationData = @{ InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' UpdateEnabled = 'False' - #UpdateSource = "$env:TEMP\SqlUpdates" SuppressReboot = $true # Make sure we don't reboot during testing. ForceReboot = $false @@ -212,7 +211,6 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot @@ -308,7 +306,6 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineDefaultInstanceAsUser_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot SQLSysAdminAccounts = @( @@ -377,7 +374,6 @@ Configuration MSFT_SqlSetup_InstallTabularAnalysisServicesAsSystem_Config InstallSharedDir = $Node.InstallSharedDir InstallSharedWOWDir = $Node.InstallSharedWOWDir UpdateEnabled = $Node.UpdateEnabled - #UpdateSource = $Node.UpdateSource SuppressReboot = $Node.SuppressReboot ForceReboot = $Node.ForceReboot From 8bb2ee8deafb75b220698f5a7e0959fc5f8643e9 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 20 Jan 2019 19:08:31 +0100 Subject: [PATCH 18/18] Fix review comments at r4 --- Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 | 2 +- Tests/Integration/MSFT_SqlSetup.config.ps1 | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index 6e170142d..942872135 100644 --- a/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -122,7 +122,7 @@ try Invoke-WebRequest -Uri $mockSourceMediaUrl -OutFile $mockIsoMediaFilePath - Write-Verbose -Message ('SQL Server media file has hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath -Algorithm 'SHA384').Hash) -Verbose + Write-Verbose -Message ('SQL Server media file has SHA1 hash ''{0}''' -f (Get-FileHash -Path $mockIsoMediaFilePath -Algorithm 'SHA1').Hash) -Verbose $ProgressPreference = $previousProgressPreference diff --git a/Tests/Integration/MSFT_SqlSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 index 141b3376b..9556c2d51 100644 --- a/Tests/Integration/MSFT_SqlSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -43,7 +43,6 @@ $ConfigurationData = @{ # Properties for mounting media ImagePath = "$env:TEMP\SQL2016.iso" - #ImagePathServicePack = "$env:TEMP\SqlUpdates\SQLServer2016SP2-KB4052908-x64-ENU.exe" DriveLetter = $mockIsoMediaDriveLetter CertificateFile = $env:DscPublicCertificatePath