Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 26, 2024
1 parent 7d0dbf9 commit 4f76ace
Show file tree
Hide file tree
Showing 45 changed files with 2,080 additions and 1,065 deletions.
6 changes: 3 additions & 3 deletions .aider/aider.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Update-PesterTest {
.PARAMETER MaxFileSize
The maximum size of test files to process, in bytes. Files larger than this will be skipped.
Defaults to 8KB.
Defaults to 7.5kb.
.PARAMETER Model
The AI model to use (e.g., azure/gpt-4o, gpt-4o-mini, claude-3-5-sonnet).
Expand Down Expand Up @@ -64,7 +64,7 @@ function Update-PesterTest {
[int]$Skip,
[string[]]$PromptFilePath = "/workspace/.aider/prompts/template.md",
[string[]]$CacheFilePath = @("/workspace/.aider/prompts/conventions.md","/workspace/private/testing/Get-TestConfig.ps1"),
[int]$MaxFileSize = 8kb,
[int]$MaxFileSize = 7.5kb,
[string]$Model
)
begin {
Expand Down Expand Up @@ -391,7 +391,7 @@ function Repair-SmallThing {
}

# if file is larger than MaxFileSize, skip
if ((Get-Item $filename).Length -gt 8kb) {
if ((Get-Item $filename).Length -gt 7.5kb) {
Write-Warning "Skipping $cmdName because it's too large"
continue
}
Expand Down
64 changes: 44 additions & 20 deletions tests/Copy-DbaAgentProxy.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'ProxyAccount', 'ExcludeProxyAccount', 'Force', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Describe "Copy-DbaAgentProxy" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaAgentProxy
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"ProxyAccount",
"ExcludeProxyAccount",
"Force",
"EnableException",
"Confirm",
"WhatIf"
)
}

It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
Describe "Copy-DbaAgentProxy" -Tag "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'"
Expand All @@ -25,6 +46,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'"
$server.Query($sql)
}

AfterAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'"
Expand All @@ -39,17 +61,19 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$server.Query($sql)
}

Context "Copies Agent Proxy" {
$results = Copy-DbaAgentProxy -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -ProxyAccount dbatoolsci_agentproxy
Context "When copying agent proxy between instances" {
BeforeAll {
$results = Copy-DbaAgentProxy -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -ProxyAccount dbatoolsci_agentproxy
}

It "returns one results" {
$results.Count -eq 1
$results.Status -eq "Successful"
It "Should return one successful result" {
$results.Count | Should -Be 1
$results.Status | Should -Be "Successful"
}

It "return one result that's skipped" {
$results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance3 -Proxy dbatoolsci_agentproxy
$results.Count -eq 1
It "Should create the proxy on the destination" {
$proxyResults = Get-DbaAgentProxy -SqlInstance $TestConfig.instance3 -Proxy dbatoolsci_agentproxy
$proxyResults.Count | Should -Be 1
}
}
}
67 changes: 47 additions & 20 deletions tests/Copy-DbaAgentSchedule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'Force', 'EnableException', 'Schedule', 'Id', 'InputObject'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Describe "Copy-DbaAgentSchedule" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaAgentSchedule
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"Schedule",
"Id",
"InputObject",
"Force",
"EnableException",
"Confirm",
"WhatIf"
)
}

It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
Describe "Copy-DbaAgentSchedule" -Tag "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "EXEC msdb.dbo.sp_add_schedule @schedule_name = N'dbatoolsci_DailySchedule' , @freq_type = 4, @freq_interval = 1, @active_start_time = 010000"
$server.Query($sql)
}

AfterAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
Expand All @@ -27,20 +50,24 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance3
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
$server.Query($sql)

}

Context "Copies Agent Schedule" {
$results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3
Context "When copying agent schedule between instances" {
BeforeAll {
$results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3
}

It "returns one results" {
It "Returns more than one result" {
$results.Count | Should -BeGreaterThan 1
($results | Where Status -eq "Successful") | Should -Not -Be $null
}

It "return one result of Start Time 1:00 AM" {
$results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule
$results.ActiveStartTimeOfDay -eq '01:00:00'
It "Contains at least one successful copy" {
$results | Where-Object Status -eq "Successful" | Should -Not -BeNullOrEmpty
}

It "Creates schedule with correct start time" {
$schedule = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule
$schedule.ActiveStartTimeOfDay | Should -Be '01:00:00'
}
}
}
49 changes: 33 additions & 16 deletions tests/Copy-DbaAgentServer.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'DisableJobsOnDestination', 'DisableJobsOnSource', 'ExcludeServerProperties', 'Force', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
Describe "Copy-DbaAgentServer" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaAgentServer
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"DisableJobsOnDestination",
"DisableJobsOnSource",
"ExcludeServerProperties",
"Force",
"EnableException",
"Confirm",
"WhatIf"
)
}

It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasParams = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasParams | Should -BeNullOrEmpty
}
}
}
<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidence.
#>
}
102 changes: 62 additions & 40 deletions tests/Copy-DbaBackupDevice.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,54 +1,76 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'BackupDevice', 'Force', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0

Describe "Copy-DbaBackupDevice" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaBackupDevice
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"BackupDevice",
"Force",
"EnableException",
"Confirm",
"WhatIf"
)
}

It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

if (-not $env:appveyor) {
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Setup" {
BeforeAll {
$devicename = "dbatoolsci-backupdevice"
$backupdir = (Get-DbaDefaultPath -SqlInstance $TestConfig.instance1).Backup
$backupfilename = "$backupdir\$devicename.bak"
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance1
$server.Query("EXEC master.dbo.sp_addumpdevice @devtype = N'disk', @logicalname = N'$devicename',@physicalname = N'$backupfilename'")
$server.Query("BACKUP DATABASE master TO DISK = '$backupfilename'")
}
AfterAll {
$server.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'")
$server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance2
try {
$server1.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'")
} catch {
# don't care
}
Get-ChildItem -Path $backupfilename | Remove-Item
Describe "Copy-DbaBackupDevice" -Tag "IntegrationTests" {
BeforeAll {
$deviceName = "dbatoolsci-backupdevice"
$backupDir = (Get-DbaDefaultPath -SqlInstance $TestConfig.instance1).Backup
$backupFileName = "$backupDir\$deviceName.bak"
$sourceServer = Connect-DbaInstance -SqlInstance $TestConfig.instance1
$sourceServer.Query("EXEC master.dbo.sp_addumpdevice @devtype = N'disk', @logicalname = N'$deviceName',@physicalname = N'$backupFileName'")
$sourceServer.Query("BACKUP DATABASE master TO DISK = '$backupFileName'")
}

AfterAll {
$sourceServer.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$deviceName'")
$destServer = Connect-DbaInstance -SqlInstance $TestConfig.instance2
try {
$destServer.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$deviceName'")
} catch {
# Device may not exist, ignore error
}
Get-ChildItem -Path $backupFileName | Remove-Item
}

$results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null
if ($warn) {
It "warns if it has a problem moving (issue for local to local)" {
$warn | Should -Match "backup device to destination"
}
} else {
It "should report success" {
$results.Status | Should Be "Successful"
Context "When copying backup device between instances" {
It "Should copy the backup device successfully or warn about local copy" {
$results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -WarningVariable warning -WarningAction SilentlyContinue 3> $null

if ($warning) {
$warning | Should -Match "backup device to destination"
} else {
$results.Status | Should -Be "Successful"
}
}

$results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2
It "Should say skipped" {
$results.Status -ne "Successful" | Should be $true
It "Should skip copying when device already exists" {
$results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2
$results.Status | Should -Not -Be "Successful"
}
}
}
Expand Down
Loading

0 comments on commit 4f76ace

Please sign in to comment.