-
Notifications
You must be signed in to change notification settings - Fork 227
Add integration tests for Complete-SqlDscImage command #2310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
322dafb
Add integration tests for Complete-SqlDscImage command
johlju dff6cbf
Improve commands and tests
johlju d25bc21
Add integration tests for TempDB file count and server collation in I…
johlju c61024c
Add InstanceId parameter to Complete-SqlDscImage integration tests
johlju ab14724
Make InstanceId parameter mandatory in Complete-SqlDscImage and updat…
johlju 216a773
Update examples in Invoke-SetupAction and Complete-SqlDscImage to inc…
johlju d478c93
Throw exceptions instead of writing errors when SQL Server service fa…
johlju a0156d8
Improve verbose logging in integration tests to include computer name
johlju d93d467
Fix formatting of ProductKey and update regex for InstanceName in Inv…
johlju 0613849
Add mock parameter for InstallSharedWOWDir in Install-SqlDscServer tests
johlju 65ffc28
Add mock parameter for InstallSharedWOWDir in Invoke-SetupAction tests
johlju ad84bfb
Add suppression for PSAvoidUsingConvertToSecureStringWithPlainText in…
johlju 9c52ddd
Add dependency for Integration_Test_Commands_SqlServer_PreparedImage …
johlju 55b090e
Refactor credential variable names for clarity in Initialize-SqlDscRe…
johlju b9b2000
Update Invoke-SetupAction tests to suppress output from Invoke-SetupA…
johlju c79d124
Remove unused mock parameter 'InstanceId' from Complete-SqlDscImage t…
johlju 1721133
Rename test description for error handling when ConfigurationFile doe…
johlju 227dfb3
Update Invoke-SetupAction and Complete-SqlDscImage to require SqlSvcA…
johlju b39e129
Add AgtSvcAccount parameter to Invoke-SetupAction and Complete-SqlDsc…
johlju d713df4
Refactor Complete-SqlDscImage integration tests to streamline service…
johlju f045395
Remove mandatory requirement for InstanceId, AgtSvcAccount, and SqlSv…
johlju 3a4f700
Update Assert-SetupActionProperties to require InstanceId, SqlSvcAcco…
johlju acf9003
Add mandatory InstanceId requirement for PrepareImage setup action in…
johlju b034017
Remove mandatory requirement for InstanceId in PrepareImage parameter…
johlju 95a8d75
Add Remove-SqlServerFromCIImage script to clean pre-installed SQL Ser…
johlju f02088a
Fix typos in README for Remove-SqlServerFromCIImage script
johlju ae80547
Refactor Remove-SqlServerFromCIImage script to improve parameter hand…
johlju 8eeb7a2
Update Remove-SqlServerFromCIImage script to enhance Force parameter …
johlju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
tests/Integration/Commands/Complete-SqlDscImage.Integration.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Plain text used only for test credentials in CI.')] | ||
| param () | ||
|
|
||
| BeforeDiscovery { | ||
| try | ||
| { | ||
| if (-not (Get-Module -Name 'DscResource.Test')) | ||
| { | ||
| # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. | ||
| if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) | ||
| { | ||
| # Redirect all streams to $null, except the error stream (stream 2) | ||
| & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null | ||
| } | ||
|
|
||
| # If the dependencies have not been resolved, this will throw an error. | ||
| Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' | ||
| } | ||
| } | ||
| catch [System.IO.FileNotFoundException] | ||
| { | ||
| throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' | ||
| } | ||
| } | ||
|
|
||
| BeforeAll { | ||
| $script:moduleName = 'SqlServerDsc' | ||
|
|
||
| Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| # cSpell: ignore DSCSQLTEST, PrepareImage, CompleteImage | ||
| Describe 'Complete-SqlDscImage' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { | ||
| BeforeAll { | ||
| Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose | ||
|
|
||
| $computerName = Get-ComputerName | ||
| } | ||
|
|
||
| Context 'When completing a prepared SQL Server image' { | ||
| It 'Should run the command without throwing' { | ||
| # Set splatting parameters for Complete-SqlDscImage | ||
| $completeSqlDscImageParameters = @{ | ||
| AcceptLicensingTerms = $true | ||
| InstanceName = 'DSCSQLTEST' | ||
| InstanceId = 'DSCSQLTEST' | ||
| SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName | ||
| SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force | ||
| MediaPath = $env:IsoDrivePath | ||
| Verbose = $true | ||
| ErrorAction = 'Stop' | ||
| Force = $true | ||
| } | ||
|
|
||
| try | ||
| { | ||
| $null = Complete-SqlDscImage @completeSqlDscImageParameters | ||
| } | ||
| catch | ||
| { | ||
| # Output Summary.txt if it exists to help diagnose the failure | ||
| $summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue | | ||
| Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } | | ||
| Sort-Object -Property LastWriteTime -Descending | | ||
| Select-Object -First 1 | ||
|
|
||
| if ($summaryFiles) | ||
| { | ||
| Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose | ||
| Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose | ||
| Write-Verbose "==== End of Summary.txt ====" -Verbose | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose 'No Summary.txt file found.' -Verbose | ||
| } | ||
johlju marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Re-throw the original error | ||
| throw $_ | ||
| } | ||
| } | ||
| } | ||
johlju marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Context 'When completing a prepared image with service account parameters' { | ||
| It 'Should run the command without throwing' { | ||
| # Set splatting parameters for Complete-SqlDscImage with service account configuration | ||
| $completeSqlDscImageParameters = @{ | ||
| AcceptLicensingTerms = $true | ||
| InstanceName = 'DSCSQLTEST' | ||
| InstanceId = 'DSCSQLTEST' | ||
| SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName | ||
| SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force | ||
| SqlSvcStartupType = 'Automatic' | ||
| AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName | ||
| AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force | ||
| AgtSvcStartupType = 'Automatic' | ||
| BrowserSvcStartupType = 'Automatic' | ||
| SecurityMode = 'SQL' | ||
| SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
| SqlSysAdminAccounts = @( | ||
| ('{0}\SqlAdmin' -f $computerName) | ||
| ) | ||
| MediaPath = $env:IsoDrivePath | ||
| Verbose = $true | ||
| ErrorAction = 'Stop' | ||
| Force = $true | ||
| } | ||
|
|
||
| try | ||
| { | ||
| $null = Complete-SqlDscImage @completeSqlDscImageParameters | ||
| } | ||
| catch | ||
| { | ||
| # Output Summary.txt if it exists to help diagnose the failure | ||
| $summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue | | ||
| Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } | | ||
| Sort-Object -Property LastWriteTime -Descending | | ||
| Select-Object -First 1 | ||
|
|
||
| if ($summaryFiles) | ||
| { | ||
| Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose | ||
| Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose | ||
| Write-Verbose "==== End of Summary.txt ====" -Verbose | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose 'No Summary.txt file found.' -Verbose | ||
| } | ||
|
|
||
| # Re-throw the original error | ||
| throw $_ | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Context 'When completing a prepared image with SQL Server directory parameters' { | ||
| It 'Should run the command without throwing' { | ||
| # Set splatting parameters for Complete-SqlDscImage with directory configuration | ||
| $completeSqlDscImageParameters = @{ | ||
| AcceptLicensingTerms = $true | ||
| InstanceName = 'DSCSQLTEST' | ||
| InstanceId = 'DSCSQLTEST' | ||
| SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName | ||
| SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force | ||
| SqlSysAdminAccounts = @( | ||
| ('{0}\SqlAdmin' -f $computerName) | ||
| ) | ||
| InstallSqlDataDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data' | ||
| SqlBackupDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Backup' | ||
| SqlTempDbDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data' | ||
| SqlTempDbLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data' | ||
| SqlUserDbDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data' | ||
| SqlUserDbLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data' | ||
| TcpEnabled = $true | ||
| NpEnabled = $false | ||
| MediaPath = $env:IsoDrivePath | ||
| Verbose = $true | ||
| ErrorAction = 'Stop' | ||
| Force = $true | ||
| } | ||
|
|
||
| try | ||
| { | ||
| $null = Complete-SqlDscImage @completeSqlDscImageParameters | ||
| } | ||
| catch | ||
| { | ||
| # Output Summary.txt if it exists to help diagnose the failure | ||
| $summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue | | ||
| Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } | | ||
| Sort-Object -Property LastWriteTime -Descending | | ||
| Select-Object -First 1 | ||
|
|
||
| if ($summaryFiles) | ||
| { | ||
| Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose | ||
| Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose | ||
| Write-Verbose "==== End of Summary.txt ====" -Verbose | ||
| } | ||
| else | ||
| { | ||
| Write-Verbose 'No Summary.txt file found.' -Verbose | ||
| } | ||
|
|
||
| # Re-throw the original error | ||
| throw $_ | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.