Skip to content

Commit 3a792fc

Browse files
authored
Ensure module imports in tests (#2133)
1 parent 571b1d1 commit 3a792fc

File tree

152 files changed

+502
-497
lines changed

Some content is hidden

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

152 files changed

+502
-497
lines changed

.github/copilot-instructions.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PowerShell commands that should be public should always have its separate
1010
script file and the command name as the file name with the .ps1 extension,
1111
these files shall always be placed in the folder source/Public.
1212

13-
All public command names must have the noun prefixed with 'SqlDsc', e.g.
13+
All public command names must have the noun prefixed with 'SqlDsc', e.g.
1414
{Verb}-SqlDsc{Noun}.
1515

1616
Public commands may use private functions to move out logic that can be
@@ -199,8 +199,8 @@ case (`It`-block) as possible.
199199
Never test, mock or use `Should -Invoke` for `Write-Verbose` and `Write-Debug`
200200
regardless of other instructions.
201201

202-
Never use `Should -Not -Throw` to prepare for Pester v6 where it has been
203-
removed. By default the `It` block will handle any unexpected exception.
202+
Never use `Should -Not -Throw` to prepare for Pester v6 where it has been
203+
removed. By default the `It` block will handle any unexpected exception.
204204
Instead of `{ Command } | Should -Not -Throw`, use `Command` directly.
205205

206206
Unit tests should be added for all public commands, private functions and
@@ -213,7 +213,7 @@ they are testing, but should have the suffix .Tests.ps1. The unit tests
213213
should be written to cover all possible scenarios and code paths, ensuring
214214
that both edge cases and common use cases are tested.
215215

216-
All public commands should always have a test to validate parameter sets
216+
All public commands should always have a test to validate parameter sets
217217
using this template. For commands with a single parameter set:
218218

219219
```powershell
@@ -318,14 +318,14 @@ BeforeDiscovery {
318318
{
319319
if (-not (Get-Module -Name 'DscResource.Test'))
320320
{
321-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
321+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
322322
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
323323
{
324324
# Redirect all streams to $null, except the error stream (stream 2)
325325
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
326326
}
327327
328-
# If the dependencies has not been resolved, this will throw an error.
328+
# If the dependencies have not been resolved, this will throw an error.
329329
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
330330
}
331331
}
@@ -386,17 +386,17 @@ edge cases and common use cases are tested. The integration tests should
386386
also be written to test the command in a real environment, using real
387387
resources and dependencies.
388388

389-
Integration test script files for public commands must be added to a group
390-
within the 'Integration_Test_Commands_SqlServer' stage in ./azure-pipelines.yml.
391-
Choose the appropriate group number based on the dependencies of the command
392-
being tested (e.g., commands that require Database Engine should be in Group 2
389+
Integration test script files for public commands must be added to a group
390+
within the 'Integration_Test_Commands_SqlServer' stage in ./azure-pipelines.yml.
391+
Choose the appropriate group number based on the dependencies of the command
392+
being tested (e.g., commands that require Database Engine should be in Group 2
393393
or later, after the Database Engine installation tests).
394394

395-
When integration tests need the computer name in CI environments, always use
395+
When integration tests need the computer name in CI environments, always use
396396
the Get-ComputerName command, which is available in the build pipeline.
397397

398-
For integration testing commands use the information in the
399-
tests/Integration/Commands/README.md, which describes the testing environment
398+
For integration testing commands use the information in the
399+
tests/Integration/Commands/README.md, which describes the testing environment
400400
including available instances, users, credentials, and other configuration details.
401401

402402
All integration tests must use the below code block prior to the first
@@ -412,14 +412,14 @@ BeforeDiscovery {
412412
{
413413
if (-not (Get-Module -Name 'DscResource.Test'))
414414
{
415-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
415+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
416416
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
417417
{
418418
# Redirect all streams to $null, except the error stream (stream 2)
419419
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
420420
}
421421
422-
# If the dependencies has not been resolved, this will throw an error.
422+
# If the dependencies have not been resolved, this will throw an error.
423423
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
424424
}
425425
}
@@ -445,9 +445,9 @@ class-based resources.
445445
### SQL Server Management Objects (SMO)
446446

447447
When developing commands, private functions, class-based resources, or making
448-
modifications to existing functionality, always prefer using SQL Server
449-
Management Objects (SMO) as the primary method for interacting with SQL Server.
450-
Only use T-SQL when it is not possible to achieve the desired functionality
448+
modifications to existing functionality, always prefer using SQL Server
449+
Management Objects (SMO) as the primary method for interacting with SQL Server.
450+
Only use T-SQL when it is not possible to achieve the desired functionality
451451
with SMO.
452452

453453
## Change log

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Fixed
9+
10+
- Make sure tests forcibly imports the module being tested to avoid AI failing
11+
when testing changes.
12+
813
### Added
914

1015
- Added setup workflow for GitHub Copilot.

tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}
@@ -26,7 +26,7 @@ BeforeDiscovery {
2626
BeforeAll {
2727
$script:dscModuleName = 'SqlServerDsc'
2828

29-
Import-Module -Name $script:dscModuleName
29+
Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
3030
}
3131

3232
Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {

tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Get-SqlDscRSSetupConfiguration.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Install-SqlDscBIReportServer.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

tests/Integration/Commands/Prerequisites.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ BeforeDiscovery {
66
{
77
if (-not (Get-Module -Name 'DscResource.Test'))
88
{
9-
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
1010
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
1111
{
1212
# Redirect all streams to $null, except the error stream (stream 2)
1313
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
1414
}
1515

16-
# If the dependencies has not been resolved, this will throw an error.
16+
# If the dependencies have not been resolved, this will throw an error.
1717
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
1818
}
1919
}

0 commit comments

Comments
 (0)