Skip to content

Commit 7310231

Browse files
committed
Refactor module name usage in tests and remove unnecessary -Force flag from Import-Module
1 parent 037c1d7 commit 7310231

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

tests/Unit/Classes/SqlDatabase.Tests.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ BeforeDiscovery {
3030
}
3131

3232
BeforeAll {
33-
$script:dscModuleName = 'SqlServerDsc'
33+
$script:moduleName = 'SqlServerDsc'
3434

3535
$env:SqlServerDscCI = $true
3636

37-
Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
37+
# Do not use -Force. Doing so, or unloading the module in AfterAll, causes
38+
# PowerShell class types to get new identities, breaking type comparisons.
39+
Import-Module -Name $script:moduleName -ErrorAction 'Stop'
3840

3941
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '../../TestHelpers/CommonTestHelper.psm1')
4042

@@ -44,19 +46,16 @@ BeforeAll {
4446
# Load the correct SQL Module stub
4547
$script:stubModuleName = Import-SQLModuleStub -PassThru
4648

47-
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscModuleName
48-
$PSDefaultParameterValues['Mock:ModuleName'] = $script:dscModuleName
49-
$PSDefaultParameterValues['Should:ModuleName'] = $script:dscModuleName
49+
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
50+
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
51+
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
5052
}
5153

5254
AfterAll {
5355
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
5456
$PSDefaultParameterValues.Remove('Mock:ModuleName')
5557
$PSDefaultParameterValues.Remove('Should:ModuleName')
5658

57-
# Unload the module being tested so that it doesn't impact any other tests.
58-
Get-Module -Name $script:dscModuleName -All | Remove-Module -Force
59-
6059
# Unload the stub module.
6160
Remove-SqlModuleStub -Name $script:stubModuleName
6261

tests/Unit/Public/New-SqlDscDatabaseSnapshot.Tests.ps1

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
22
param ()
33

4-
<#
5-
TODO: This fails with:
6-
7-
Running tests from 'D:\a\1\s\tests\Unit\Public\New-SqlDscDatabaseSnapshot.Tests.ps1'
8-
Describing New-SqlDscDatabaseSnapshot
9-
Context When creating a database snapshot using ServerObject parameter set
10-
##[error] [-] Should create a database snapshot successfully with minimal parameters 28ms (25ms|3ms)
11-
##[error] PSInvalidCastException: Cannot convert the "DatabaseFileSpec" value of type "DatabaseFileSpec" to type "DatabaseFileSpec".
12-
##[error] ArgumentTransformationMetadataException: Cannot convert the "DatabaseFileSpec" value of type "DatabaseFileSpec" to type "DatabaseFileSpec".
13-
##[error] ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'Files'. Cannot convert the "DatabaseFileSpec" value of type "DatabaseFileSpec" to type "DatabaseFileSpec".
14-
##[error] at New-SqlDscDatabaseSnapshot<Process>, D:\a\1\s\output\builtModule\SqlServerDsc\17.4.0\SqlServerDsc.psm1:20649
15-
##[error] at <ScriptBlock>, D:\a\1\s\tests\Unit\Public\New-SqlDscDatabaseSnapshot.Tests.ps1:137
16-
#>
17-
return
18-
194
BeforeDiscovery {
205
try
216
{

0 commit comments

Comments
 (0)