Skip to content

Commit 2740d7d

Browse files
Pester migration - Third batch (#9531)
1 parent f2d3146 commit 2740d7d

File tree

47 files changed

+2113
-1106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2113
-1106
lines changed

.aider/aider.psm1

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function Update-PesterTest {
2727
2828
.PARAMETER MaxFileSize
2929
The maximum size of test files to process, in bytes. Files larger than this will be skipped.
30-
Defaults to 8KB.
30+
Defaults to 7.5kb.
31+
32+
.PARAMETER Model
33+
The AI model to use (e.g., azure/gpt-4o, gpt-4o-mini, claude-3-5-sonnet).
3134
3235
.NOTES
3336
Tags: Testing, Pester
@@ -61,7 +64,8 @@ function Update-PesterTest {
6164
[int]$Skip,
6265
[string[]]$PromptFilePath = "/workspace/.aider/prompts/template.md",
6366
[string[]]$CacheFilePath = @("/workspace/.aider/prompts/conventions.md","/workspace/private/testing/Get-TestConfig.ps1"),
64-
[int]$MaxFileSize = 8kb
67+
[int]$MaxFileSize = 7.5kb,
68+
[string]$Model
6569
)
6670
begin {
6771
# Full prompt path
@@ -158,9 +162,10 @@ function Update-PesterTest {
158162
Message = $cmdPrompt
159163
File = $filename
160164
YesAlways = $true
161-
Stream = $false
165+
NoStream = $true
162166
CachePrompts = $true
163167
ReadFile = $CacheFilePath
168+
Model = $Model
164169
}
165170

166171
Write-Verbose "Invoking Aider to update test file"
@@ -244,7 +249,7 @@ function Repair-Error {
244249
$aiderParams = @{
245250
Message = $cmdPrompt
246251
File = $filename
247-
Stream = $false
252+
NoStream = $true
248253
CachePrompts = $true
249254
ReadFile = $CacheFilePath
250255
}
@@ -386,7 +391,7 @@ function Repair-SmallThing {
386391
}
387392

388393
# if file is larger than MaxFileSize, skip
389-
if ((Get-Item $filename).Length -gt 8kb) {
394+
if ((Get-Item $filename).Length -gt 7.5kb) {
390395
Write-Warning "Skipping $cmdName because it's too large"
391396
continue
392397
}
@@ -715,7 +720,7 @@ function Repair-Error {
715720
$aiderParams = @{
716721
Message = $cmdPrompt
717722
File = $filename
718-
Stream = $false
723+
NoStream = $true
719724
CachePrompts = $true
720725
ReadFile = $CacheFilePath
721726
}

.aider/prompts/conventions.md

+39-29
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,27 @@ Describe "Add-DbaAgReplica" -Tag "IntegrationTests" {
126126

127127
```powershell
128128
Describe "Get-DbaDatabase" -Tag "UnitTests" {
129-
Context "Parameter validation" {
130-
BeforeAll {
131-
$command = Get-Command Get-DbaDatabase
132-
$expected = $TestConfig.CommonParameters
133-
$expected += @(
134-
"SqlInstance",
135-
"SqlCredential",
136-
"Database",
137-
"Confirm",
138-
"WhatIf"
139-
)
140-
}
141-
142-
It "Has parameter: <_>" -ForEach $expected {
143-
$command | Should -HaveParameter $PSItem
144-
}
145-
146-
It "Should have exactly the number of expected parameters ($($expected.Count))" {
147-
$hasparms = $command.Parameters.Values.Name
148-
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
149-
}
150-
}
129+
BeforeAll {
130+
$command = Get-Command Get-DbaDatabase
131+
$expected = $TestConfig.CommonParameters
132+
$expected += @(
133+
"SqlInstance",
134+
"SqlCredential",
135+
"Database",
136+
"Confirm",
137+
"WhatIf"
138+
)
139+
}
140+
Context "Parameter validation" {
141+
It "Has parameter: <_>" -ForEach $expected {
142+
$command | Should -HaveParameter $PSItem
143+
}
144+
145+
It "Should have exactly the number of expected parameters ($($expected.Count))" {
146+
$hasparms = $command.Parameters.Values.Name
147+
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
148+
}
149+
}
151150
}
152151
```
153152

@@ -172,11 +171,22 @@ Describe "Get-DbaDatabase" -Tag "IntegrationTests" {
172171
}
173172
```
174173

175-
## Additional instructions
174+
## Additional Instructions
175+
176+
### Test Structure
177+
- Parameter validation must be tagged as Unit Test
178+
- No loose code outside of proper test blocks
179+
- Must maintain all instance reference comments (#TestConfig.instance3, etc.)
180+
181+
### Syntax Requirements
182+
- Use $PSItem instead of $_
183+
- No trailing spaces
184+
- Use $results.Status.Count for accurate counting
185+
186+
### Must Not Use
187+
- $MyInvocation.MyCommand.Name for command names
188+
- Old knownParameters validation approach
189+
- Assumed parameter names - match original tests exactly
176190

177-
- DO NOT use `$MyInvocation.MyCommand.Name` to get command names
178-
- DO NOT use the old `knownParameters` validation approach
179-
- DO NOT include loose code outside of proper test blocks
180-
- DO NOT remove comments like "#TestConfig.instance3" or "#$TestConfig.instance2 for appveyor"
181-
- DO NOT use $_ DO use $PSItem instead
182-
- Parameter validation is ALWAYS tagged as a Unit Test
191+
# Important
192+
ALL comments must be preserved exactly as they appear in the original code, including seemingly unrelated or end-of-file comments. Even comments that appear to be development notes or temporary must be kept. This is especially important for comments related to CI/CD systems like AppVeyor.

tests/Copy-DbaAgentProxy.Tests.ps1

+44-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
2-
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
3-
$global:TestConfig = Get-TestConfig
4-
5-
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
6-
Context "Validate parameters" {
7-
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
8-
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'ProxyAccount', 'ExcludeProxyAccount', 'Force', 'EnableException'
9-
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
10-
It "Should only contain our specific parameters" {
11-
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
1+
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
2+
param(
3+
$ModuleName = "dbatools",
4+
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
5+
)
6+
7+
Describe "Copy-DbaAgentProxy" -Tag "UnitTests" {
8+
Context "Parameter validation" {
9+
BeforeAll {
10+
$command = Get-Command Copy-DbaAgentProxy
11+
$expected = $TestConfig.CommonParameters
12+
$expected += @(
13+
"Source",
14+
"SourceSqlCredential",
15+
"Destination",
16+
"DestinationSqlCredential",
17+
"ProxyAccount",
18+
"ExcludeProxyAccount",
19+
"Force",
20+
"EnableException",
21+
"Confirm",
22+
"WhatIf"
23+
)
24+
}
25+
26+
It "Has parameter: <_>" -ForEach $expected {
27+
$command | Should -HaveParameter $PSItem
28+
}
29+
30+
It "Should have exactly the number of expected parameters ($($expected.Count))" {
31+
$hasparms = $command.Parameters.Values.Name
32+
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
1233
}
1334
}
1435
}
1536

16-
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
37+
Describe "Copy-DbaAgentProxy" -Tag "IntegrationTests" {
1738
BeforeAll {
1839
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
1940
$sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'"
@@ -25,6 +46,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
2546
$sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'"
2647
$server.Query($sql)
2748
}
49+
2850
AfterAll {
2951
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
3052
$sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'"
@@ -39,17 +61,19 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
3961
$server.Query($sql)
4062
}
4163

42-
Context "Copies Agent Proxy" {
43-
$results = Copy-DbaAgentProxy -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -ProxyAccount dbatoolsci_agentproxy
64+
Context "When copying agent proxy between instances" {
65+
BeforeAll {
66+
$results = Copy-DbaAgentProxy -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -ProxyAccount dbatoolsci_agentproxy
67+
}
4468

45-
It "returns one results" {
46-
$results.Count -eq 1
47-
$results.Status -eq "Successful"
69+
It "Should return one successful result" {
70+
$results.Status.Count | Should -Be 1
71+
$results.Status | Should -Be "Successful"
4872
}
4973

50-
It "return one result that's skipped" {
51-
$results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance3 -Proxy dbatoolsci_agentproxy
52-
$results.Count -eq 1
74+
It "Should create the proxy on the destination" {
75+
$proxyResults = Get-DbaAgentProxy -SqlInstance $TestConfig.instance3 -Proxy dbatoolsci_agentproxy
76+
$proxyResults.Name | Should -Be "dbatoolsci_agentproxy"
5377
}
5478
}
5579
}

tests/Copy-DbaAgentSchedule.Tests.ps1

+47-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1-
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
2-
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
3-
$global:TestConfig = Get-TestConfig
4-
5-
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
6-
Context "Validate parameters" {
7-
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
8-
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'Force', 'EnableException', 'Schedule', 'Id', 'InputObject'
9-
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
10-
It "Should only contain our specific parameters" {
11-
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
1+
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
2+
param(
3+
$ModuleName = "dbatools",
4+
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
5+
)
6+
7+
Describe "Copy-DbaAgentSchedule" -Tag "UnitTests" {
8+
Context "Parameter validation" {
9+
BeforeAll {
10+
$command = Get-Command Copy-DbaAgentSchedule
11+
$expected = $TestConfig.CommonParameters
12+
$expected += @(
13+
"Source",
14+
"SourceSqlCredential",
15+
"Destination",
16+
"DestinationSqlCredential",
17+
"Schedule",
18+
"Id",
19+
"InputObject",
20+
"Force",
21+
"EnableException",
22+
"Confirm",
23+
"WhatIf"
24+
)
25+
}
26+
27+
It "Has parameter: <_>" -ForEach $expected {
28+
$command | Should -HaveParameter $PSItem
29+
}
30+
31+
It "Should have exactly the number of expected parameters ($($expected.Count))" {
32+
$hasparms = $command.Parameters.Values.Name
33+
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
1234
}
1335
}
1436
}
1537

16-
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
38+
Describe "Copy-DbaAgentSchedule" -Tag "IntegrationTests" {
1739
BeforeAll {
1840
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
1941
$sql = "EXEC msdb.dbo.sp_add_schedule @schedule_name = N'dbatoolsci_DailySchedule' , @freq_type = 4, @freq_interval = 1, @active_start_time = 010000"
2042
$server.Query($sql)
2143
}
44+
2245
AfterAll {
2346
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
2447
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
@@ -27,20 +50,24 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
2750
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance3
2851
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
2952
$server.Query($sql)
30-
3153
}
3254

33-
Context "Copies Agent Schedule" {
34-
$results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3
55+
Context "When copying agent schedule between instances" {
56+
BeforeAll {
57+
$results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3
58+
}
3559

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

41-
It "return one result of Start Time 1:00 AM" {
42-
$results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule
43-
$results.ActiveStartTimeOfDay -eq '01:00:00'
64+
It "Contains at least one successful copy" {
65+
$results | Where-Object Status -eq "Successful" | Should -Not -BeNullOrEmpty
66+
}
67+
68+
It "Creates schedule with correct start time" {
69+
$schedule = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule
70+
$schedule.ActiveStartTimeOfDay | Should -Be '01:00:00'
4471
}
4572
}
4673
}

tests/Copy-DbaAgentServer.Tests.ps1

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
2-
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
3-
$global:TestConfig = Get-TestConfig
1+
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
2+
param(
3+
$ModuleName = "dbatools",
4+
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
5+
)
46

5-
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
6-
Context "Validate parameters" {
7-
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
8-
[object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'DisableJobsOnDestination', 'DisableJobsOnSource', 'ExcludeServerProperties', 'Force', 'EnableException'
9-
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
10-
It "Should only contain our specific parameters" {
11-
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
7+
Describe "Copy-DbaAgentServer" -Tag "UnitTests" {
8+
Context "Parameter validation" {
9+
BeforeAll {
10+
$command = Get-Command Copy-DbaAgentServer
11+
$expected = $TestConfig.CommonParameters
12+
$expected += @(
13+
"Source",
14+
"SourceSqlCredential",
15+
"Destination",
16+
"DestinationSqlCredential",
17+
"DisableJobsOnDestination",
18+
"DisableJobsOnSource",
19+
"ExcludeServerProperties",
20+
"Force",
21+
"EnableException",
22+
"Confirm",
23+
"WhatIf"
24+
)
25+
}
26+
27+
It "Has parameter: <_>" -ForEach $expected {
28+
$command | Should -HaveParameter $PSItem
29+
}
30+
31+
It "Should have exactly the number of expected parameters ($($expected.Count))" {
32+
$hasParams = $command.Parameters.Values.Name
33+
Compare-Object -ReferenceObject $expected -DifferenceObject $hasParams | Should -BeNullOrEmpty
1234
}
1335
}
14-
}
15-
<#
16-
Integration test should appear below and are custom to the command you are writing.
17-
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
18-
for more guidence.
19-
#>
36+
}

0 commit comments

Comments
 (0)