Skip to content

Commit 6c70c78

Browse files
Refactor test configuration to standardize instance naming and improve clarity in documentation (#10142)
1 parent 8770610 commit 6c70c78

File tree

7 files changed

+35
-46
lines changed

7 files changed

+35
-46
lines changed

.github/CONTRIBUTING-TESTING.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ $config['InstanceHadr'] = "YourServer\Instance2"
151151
# For tests that restart SQL Server (use with caution!)
152152
$config['InstanceRestart'] = "YourServer\Instance2"
153153
154-
# Legacy support - some older tests still use these
155-
$config['instance1'] = $config['InstanceSingle']
156-
$config['instance2'] = $config['InstanceMulti2']
157-
158154
# ============================================
159155
# Authentication
160156
# ============================================
@@ -175,9 +171,6 @@ $config['Defaults']['*:DestinationSqlCredential'] = $config['SqlCred']
175171
# Test Infrastructure
176172
# ============================================
177173
178-
# Computer name for certain tests
179-
$config['dbatoolsci_computer'] = $env:COMPUTERNAME
180-
181174
# Temp directory for test files
182175
# IMPORTANT: For remote instances, use a network share accessible by both
183176
# the SQL Server service account AND your PowerShell session

.github/copilot-instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ Context "Parameter validation" {
431431
## Environment Variables & Test Config
432432

433433
**AppVeyor test instances:**
434-
- `$script:instance1` = SQL Server 2008 R2
435-
- `$script:instance2` = SQL Server 2016
436-
- `$script:instance3` = SQL Server 2017
434+
- `$TestConfig.InstanceSingle` = SQL Server 2022
435+
- `$TestConfig.InstanceMulti1` = SQL Server 2022
436+
- `$TestConfig.InstanceMulti2` = SQL Server 2017
437437

438438
**GitHub Actions:**
439439
- Linux: `localhost`, `localhost:14333` (Docker containers)

.github/prompts/style.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ Import-Module C:\gallery\dbatools.library
353353
$TestConfig = Get-TestConfig
354354
355355
# 3. Now you can use $TestConfig properties in your tests
356-
$TestConfig.instance1 # First test SQL instance
357-
$TestConfig.instance2 # Second test SQL instance
358-
$TestConfig.instance3 # Third test SQL instance
359-
$TestConfig.SqlCred # Test credentials, all connections need this
360-
$TestConfig.Temp # Temp directory for test files
356+
$TestConfig.InstanceSingle # Test SQL instance for tests that only need one instance
357+
$TestConfig.InstanceMulti1 # First test SQL instance for tests that need multiple instances
358+
$TestConfig.InstanceMulti2 # Second test SQL instance for tests that need multiple instances
359+
$TestConfig.SqlCred # Test credentials, all connections need this
360+
$TestConfig.Temp # Temp directory for test files
361361
362362
# 4. Set the default params for sqlcred
363363
$PSDefaultParameterValues["*:SqlCredential"] = $TestConfig.SqlCred

CONTRIBUTING.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,18 @@ You can inspect/copy/cannibalize existing tests. You'll see that every test file
130130

131131
## AppVeyor Environment
132132

133-
AppVeyor is hooked up to test any commit, including PRs. Each commit triggers 5 builds, each referred to as a "scenario". We have the scenarios setup where the dbatools log is published as an artifact should you need to view why test are failing.
133+
AppVeyor is hooked up to test any commit, including PRs. Each commit triggers several builds, each referred to as a "scenario". We have the scenarios setup where the dbatools log is published as an artifact should you need to view why test are failing.
134134

135-
- 2008R2 : a server with a single SQL Server 2008 R2 Express Edition instance available ($script:instance1)
136-
- 2016 : a server with a single SQL Server 2016 Developer Edition instance available ($script:instance2)
137-
- 2016_service: used to test service restarts
138-
- 2016_2017 : a server with two instances available, 2016 and 2017 Developer Edition
139-
- default: a server with two instances available, one SQL Server 2008 R2 Express Edition and a SQL Server 2016 Developer Edition
135+
- SINGLE: a server with a single SQL Server 2022 instance available ($TestConfig.InstanceSingle)
136+
- MULTI: a server with two instances (SQL Server 2022 and SQL Server 2017) available for tests that need multiple instances ($TestConfig.InstanceMulti1 and $TestConfig.InstanceMulti2)
137+
- COPY: a server with two instances (SQL Server 2017 and SQL Server 2022) available for tests that need multiple instances ($TestConfig.InstanceCopy1 and $TestConfig.InstanceCopy2)
138+
- HADR: a single SQL Server 2022 instance available with Hadr configured ($TestConfig.InstanceHadr)
139+
- RESTART: used to test service restarts ($TestConfig.InstanceRestart)
140+
- 2008R2SP2Express: a server with a single SQL Server 2008 R2 Express Edition available to test some commands against an old version ($TestConfig.InstanceSingle)
141+
- default: a server with no instance for all tests that don't need a running instance
140142

141143
Builds are split among "scenario"(s) because not every test requires everything to be up and running, and resources on AppVeyor are constrained.
142-
143-
Ideally:
144-
145-
1. Whenever possible, write UnitTests.
146-
2. You should write IntegrationTests ideally running in **EITHER** the 2008R2 or the 2016 "scenario".
147-
3. Default and 2016_2017 are the most resource constrained and are left to run the Copy-* commands which are the only ones **needing** two active instances.
148-
4. If you want to write tests that, e.g, target **BOTH** 2008R2 and 2016, try to avoid writing tests that need both instances to be active at the same time.
149-
150-
AppVeyor is set up to recognize what "scenario" is required by your test, simply inspecting for the presence of combinations of `$script:instance1`, `$script:instance2` and `$script:instance3`. If you need to fall into case (4), write two test files, e.g. _Get-DbaFoo.first.Tests.ps1_ (targeting `$script:instance1` only) and _Get-DbaFoo.second.Tests.ps1_ (targeting `$script:instance2` only).
144+
AppVeyor is set up to recognize what "scenario" is required by your test, simply inspecting for the presence of $TestConfig.Instance*.
151145

152146
Most PRs will target `public/*.ps1` files to add functionality or resolve bugs.
153147
Our test runner will try and figure out what tests needs to be run based on the files modified in the PR, plus all the dependencies.

private/testing/Get-TestConfig.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ function Get-TestConfig {
6161
} elseif ($env:CODESPACES -or ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) {
6262
$null = Set-DbatoolsInsecureConnection
6363

64-
$config['Instance1'] = "dbatools1"
65-
$config['Instance2'] = "dbatools2"
64+
$config['InstanceSingle'] = "dbatools1"
65+
$config['InstanceMulti1'] = "dbatools1"
66+
$config['InstanceMulti2'] = "dbatools2"
6667

6768
$config['SqlCred'] = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force))
6869
$config['Defaults']['*:SqlCredential'] = $config['SqlCred']
6970
$config['Defaults']['*:SourceSqlCredential'] = $config['SqlCred']
7071
$config['Defaults']['*:DestinationSqlCredential'] = $config['SqlCred']
7172
} elseif ($env:GITHUB_WORKSPACE) {
72-
$config['DbaToolsCi_Computer'] = "localhost"
73-
74-
$config['Instance1'] = "localhost"
75-
$config['Instance2'] = "localhost:14333"
73+
$config['InstanceSingle'] = "localhost"
74+
$config['InstanceMulti1'] = "localhost"
75+
$config['InstanceMulti2'] = "localhost:14333"
7676

7777
$config['SQLUserName'] = $null # placeholders for -SqlCredential testing
7878
$config['SQLPassword'] = $null

tests/CLAUDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Import-Module C:\gallery\dbatools.library
1616
$TestConfig = Get-TestConfig
1717
1818
# 3. Now you can use $TestConfig properties in your tests
19-
$TestConfig.instance1 # First test SQL instance
20-
$TestConfig.instance2 # Second test SQL instance
21-
$TestConfig.instance3 # Third test SQL instance
22-
$TestConfig.SqlCred # Test credentials, all connections need this
23-
$TestConfig.Temp # Temp directory for test files
19+
$TestConfig.InstanceSingle # Test SQL instance for tests that only need one instance
20+
$TestConfig.InstanceMulti1 # First test SQL instance for tests that need multiple instances
21+
$TestConfig.InstanceMulti2 # Second test SQL instance for tests that need multiple instances
22+
$TestConfig.SqlCred # Test credentials, all connections need this
23+
$TestConfig.Temp # Temp directory for test files
2424
# 4. Set the default paras for sqlcred
2525
$PSDefaultParameterValues["*:SqlCredential"] = $TestConfig.SqlCred
2626
```

tests/constants.local.ps1.example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
# Modify the $config hashtable to include your custom configurations.
55

66
# Define your local SQL Server instances
7-
$config['instance1'] = "localhost\SQLInstance1" # Replace with your first SQL Server instance
8-
$config['instance2'] = "localhost\SQLInstance2" # Replace with your second SQL Server instance
7+
$config['InstanceSingle'] = "localhost\SQLInstance1"
8+
$config['InstanceMulti1'] = "localhost\SQLInstance1"
9+
$config['InstanceMulti2'] = "localhost\SQLInstance2"
10+
$config['InstanceCopy1'] = "localhost\SQLInstance1"
11+
$config['InstanceCopy2'] = "localhost\SQLInstance2"
12+
$config['InstanceHadr'] = "localhost\SQLInstance1"
13+
$config['InstanceRestart'] = "localhost\SQLInstance1"
914

1015
# SQL Server credentials
1116
# Replace 'YourPassword' with your actual password and 'sa' with your username if different
@@ -17,9 +22,6 @@ $config['Defaults'] = [System.Management.Automation.DefaultParameterDictionary]@
1722
"*:SqlCredential" = $config['SqlCred']
1823
}
1924

20-
# Additional configurations
21-
$config['dbatoolsci_computer'] = "localhost" # Replace if your CI computer is different
22-
2325
# If using SQL authentication for Instance2, specify the username and password
2426
$config['SQLUserName'] = $null # Replace with username if applicable
2527
$config['SQLPassword'] = $null # Replace with password if applicable

0 commit comments

Comments
 (0)