Skip to content

Commit 646ae8d

Browse files
committed
Cleaned up tests
1 parent dc29f52 commit 646ae8d

17 files changed

Lines changed: 124 additions & 52 deletions

functions/Initialize-PDCVhdDisk.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function Initialize-PDCVhdDisk {
1515
1616
$scred = Get-Credential, then pass $scred object to the -Credential parameter.
1717
18+
.PARAMETER PartitionStyle
19+
A partition can either be initialized as MBR or as GPT. GPT is the default.
20+
21+
.PARAMETER AllocationUnitSize
22+
Set the allocation unit size for the disk.
23+
By default it's 64 KB because that's what SQL Server tends to write most of the time.
24+
1825
.PARAMETER EnableException
1926
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
2027
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.

functions/Invoke-PDCRepairClone.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,13 @@ function Invoke-PDCRepairClone {
107107
# Loop through the results
108108
foreach ($result in $results) {
109109

110-
$disk = $null
111-
112110
# Get the databases
113111
Write-PSFMessage -Message "Retrieve the databases for $($result.SqlInstance)" -Level Verbose
114112
$databases = Get-DbaDatabase -SqlInstance $result.SqlInstance -SqlCredential $SqlCredential
115113

116114
# Check if the parent of the clone can be reached
117115
if (Test-Path -Path $result.ImageLocation) {
118116

119-
# Get the disk
120-
$disk = Get-VHD -Path $result.CloneLocation
121-
122117
# Mount the clone
123118
try {
124119
Write-PSFMessage -Message "Mounting vhd $($result.CloneLocation)" -Level Verbose

functions/New-PDCClone.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function New-PDCClone {
3535
.PARAMETER Database
3636
Database name for the clone
3737
38+
.PARAMETER LatestImage
39+
Automatically get the last image ever created for an specific database
40+
3841
.PARAMETER Disabled
3942
Registers the clone in the configuration as disabled.
4043
If this setting is used the clone will not be recovered when the repair command is run
@@ -78,7 +81,7 @@ function New-PDCClone {
7881
7982
Create a new clone on SQLDB1 and SQLDB2 for the databases DB1 with the latest image
8083
#>
81-
[CmdLetBinding(DefaultParameterSetName = 'ByLatest')]
84+
[CmdLetBinding(DefaultParameterSetName = 'ByLatest', SupportsShouldProcess = $true)]
8285
param(
8386
[parameter(Mandatory = $true)]
8487
[ValidateNotNullOrEmpty()]
@@ -213,7 +216,7 @@ function New-PDCClone {
213216
$result = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query -EnableException
214217

215218
# Check the results
216-
if ($result -eq $null) {
219+
if ($null -eq $result) {
217220
Stop-PSFFunction -Message "No image could be found for database $db" -Target $pdcSqlInstance -Continue
218221
}
219222
else {
@@ -405,7 +408,7 @@ function New-PDCClone {
405408
}
406409

407410

408-
if ($imageId -ne $null) {
411+
if ($null -ne $imageId) {
409412

410413
$cloneLocation = "$Destination\$CloneName.vhdx"
411414

functions/New-PDCImage.ps1

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function New-PDCImage {
3939
4040
$scred = Get-Credential, then pass $scred object to the -DestinationCredential parameter.
4141
42-
.PARAMETER ImageLocalPath
42+
.PARAMETER ImageNetworkPath
4343
Network path where to save the image. This has to be a UNC path
4444
4545
.PARAMETER ImageLocalPath
@@ -89,7 +89,7 @@ function New-PDCImage {
8989
Create an image from the database DB1 on SQLDB1 using the last full backup and use SQLDB2 as the temporary database server.
9090
The image is written to c:\Temp\images
9191
#>
92-
[CmdLetBinding()]
92+
[CmdLetBinding(SupportsShouldProcess = $true)]
9393
param(
9494
[parameter(Mandatory = $true)]
9595
[ValidateNotNullOrEmpty()]
@@ -212,8 +212,6 @@ function New-PDCImage {
212212
# Set time stamp
213213
$timestamp = Get-Date -format "yyyyMMddHHmmss"
214214

215-
# Create the item list array
216-
$list = @()
217215
}
218216

219217
process {
@@ -401,30 +399,6 @@ function New-PDCImage {
401399
Stop-PSFFunction -Message "Couldn't add image to database" -Target $imageName -ErrorRecord $_
402400
}
403401

404-
<# if (Test-PSFFunctionInterrupt) {
405-
Write-PSFMessage -Message "Cleaning up image after failure" -Level Verbose
406-
407-
# Clean up in case of failure
408-
try {
409-
# Check if the image was written to database
410-
if ($result.Count -ge 1) {
411-
412-
$query = "DELETE FROM Image WHERE ImageID = $($Result.ImageID)"
413-
414-
$null = Invoke-DbaSqlQuery -SqlInstance $pdcSqlInstance -Database $pdcDatabase -Query $query -EnableException
415-
}
416-
417-
# Remove file
418-
$null = Remove-Item -Path $imageLocation -Credential $DestinationCredential -Force:$Force
419-
}
420-
catch {
421-
Stop-PSFFunction -Message "Couldn't remove created image $imageLocation after failure" -Target $imageLocation -ErrorRecord $_ -Continue
422-
}
423-
}
424-
else {
425-
426-
} #>
427-
428402
# Add the results to the custom object
429403
[PSCustomObject]@{
430404
Name = $imageName

functions/New-PDCVhdDisk.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function New-PDCVhdDisk {
5656
5757
#>
5858

59-
[CmdLetBinding()]
59+
[CmdLetBinding(SupportsShouldProcess = $true)]
6060

6161
param(
6262
[parameter(Mandatory = $true)]

functions/Remove-PDCClone.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function Remove-PDCClone {
3434
.PARAMETER ExcludeDatabase
3535
Allows to filter to exclude specific databases
3636
37+
.PARAMETER All
38+
Remove all the clones
39+
40+
.PARAMETER InputObject
41+
The input object that is used for pipeline use
42+
3743
.PARAMETER EnableException
3844
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
3945
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.

functions/Remove-PDCImage.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ function Remove-PDCImage {
1818
.PARAMETER Force
1919
Forcefully remove the items.
2020
21+
.PARAMETER EnableException
22+
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
23+
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
24+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
25+
26+
.PARAMETER WhatIf
27+
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
28+
29+
.PARAMETER Confirm
30+
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
31+
2132
.NOTES
2233
Author: Sander Stad (@sqlstad, sqlstad.nl)
2334
@@ -28,8 +39,12 @@ function Remove-PDCImage {
2839
.LINK
2940
https://psdatabaseclone.io/
3041
42+
.EXAMPLE
43+
Remove-PDCImage -ImageLocation "\\server1\images\DB1_20180703193345.vhdx"
44+
45+
Remove an image
3146
#>
32-
[CmdLetBinding()]
47+
[CmdLetBinding(SupportsShouldProcess = $true)]
3348

3449
param(
3550
[parameter(Mandatory = $true)]

functions/Set-PDCConfiguration.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function Set-PDCConfiguration {
5353
5454
Set up the module to use SQLDB1 as the database servers and PSDatabaseClone to save the values in
5555
#>
56-
[CmdLetBinding()]
56+
[CmdLetBinding(SupportsShouldProcess = $true)]
5757
param(
5858
[parameter(Mandatory = $true)]
5959
[ValidateNotNullOrEmpty()]

internal/functions/Convert-PDCLocalUncPathToLocalPath.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ function Convert-PDCLocalUncPathToLocalPath {
3232
https://psdatabaseclone.io/
3333
3434
.EXAMPLE
35-
Convert-PDCLocalUncPathToLocalPath -UncPath "\\server\share"
35+
Convert-PDCLocalUncPathToLocalPath -UncPath "\\server1\share1"
36+
37+
Convert path "\\server1\share1" to a local path from server1
38+
3639
3740
#>
3841

0 commit comments

Comments
 (0)