-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F/support pester 5 #15
Conversation
Can you try to rebase the PR against my fork. In your local branch do:
When everything looks okay, make sure your changes (commit) to the tests are still there, run
|
c891c1c
to
b3cf221
Compare
Was already trying to do that, but your example made it a lot simpler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for helping in this effort! 😃
I made some comments on the first test. We should rewrite the test to be optimized for Pester 5 (not just so they work). I think I need to write some guidance around this, I can put together a blog post on dsccommunity.org.
Reviewed 1 of 3 files at r1.
Reviewable status: 1 of 3 files reviewed, 9 unresolved discussions (waiting on @Fiander)
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 76 at r2 (raw file):
-ErrorRecord $_
We should keep this as it will return the actual error as an inner exception.
Also I suggest we don't change the code when we convert to Pester 5, it is a big enough change as it is. I suggest needed changes to code should be changed in the main repo first, then we rebase those changes into the Pester 5 working branch. 🙂
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 200 at r2 (raw file):
-f $ServerName, $InstanceName, $ServerRoleName New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
Same as the previous comment.
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 227 at r2 (raw file):
-f $ServerName, $InstanceName, $ServerRoleName New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
Same as previous comment.
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 534 at r2 (raw file):
-f $ServerName, $InstanceName, $ServerRoleName, $SecurityPrincipal New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
Same as previous comment.
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 589 at r2 (raw file):
-f $ServerName, $InstanceName, $ServerRoleName, $SecurityPrincipal New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
Same as previous comment.
tests/Unit/DSC_SqlRole.Tests.ps1, line 9 at r2 (raw file):
Quoted 4 lines of code…
if (-not (Test-BuildCategory -Type 'Unit')) { return }
We can remove this, not needed with the new pipeline.
tests/Unit/DSC_SqlRole.Tests.ps1, line 15 at r2 (raw file):
Quoted 23 lines of code…
$script:dscModuleName = 'SqlServerDsc' $script:dscResourceName = 'DSC_SqlRole' function Invoke-TestSetup { try { Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' } catch [System.IO.FileNotFoundException] { throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' } $script:testEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:dscModuleName ` -DSCResourceName $script:dscResourceName ` -ResourceType 'Mof' ` -TestType 'Unit' } function Invoke-TestCleanup { Restore-TestEnvironment -TestEnvironment $script:testEnvironment } Invoke-TestSetup
This should be replaced with
SqlServerDsc/tests/Unit/DSC_SqlProtocol.Tests.ps1
Lines 6 to 40 in a7d8e44
BeforeAll { | |
$script:dscModuleName = 'SqlServerDsc' | |
$script:dscResourceName = 'DSC_SqlProtocol' | |
try | |
{ | |
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' | |
} | |
catch [System.IO.FileNotFoundException] | |
{ | |
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' | |
} | |
$script:testEnvironment = Initialize-TestEnvironment ` | |
-DSCModuleName $script:dscModuleName ` | |
-DSCResourceName $script:dscResourceName ` | |
-ResourceType 'Mof' ` | |
-TestType 'Unit' | |
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') | |
$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscResourceName | |
} | |
AfterAll { | |
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName') | |
Restore-TestEnvironment -TestEnvironment $script:testEnvironment | |
# Unload the module being tested so that it doesn't impact any other tests. | |
Get-Module -Name $script:dscResourceName -All | Remove-Module -Force | |
# Remove module common test helper. | |
Get-Module -Name 'CommonTestHelper' -All | Remove-Module -Force | |
} |
tests/Unit/DSC_SqlRole.Tests.ps1, line 42 at r2 (raw file):
try {
Try-finally-block should be removed.
tests/Unit/DSC_SqlRole.Tests.ps1, line 44 at r2 (raw file):
InModuleScope $script:dscResourceName {
InModuleScope
should only be inside Before*
-/After*
-blocks and It
-blocks. If they are not that code is run during discovery which we should avoid.
See this:
- BeforeAll-block that uses InModuleScope to set script variables in the module's scope (that will be used by it-blocks' InModuleScope):
BeforeAll { - It-block that uses
InModuleScope
:It 'Should return the correct values' { - It-block that uses
InModuleScope
with parameters:It 'Should return the correct values' { - It-block that assert
Should -Invoke
(outsideInModuleScope
):It 'Should return $true' {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 3 files reviewed, 9 unresolved discussions (waiting on @Fiander and @johlju)
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 76 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
-ErrorRecord $_
We should keep this as it will return the actual error as an inner exception.
Also I suggest we don't change the code when we convert to Pester 5, it is a big enough change as it is. I suggest needed changes to code should be changed in the main repo first, then we rebase those changes into the Pester 5 working branch. 🙂
yea, i found that one too at a later module.
there i "fixed" it by changing
in the test. that way it also works.
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 200 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Same as the previous comment.
same
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 227 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Same as previous comment.
same
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 534 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Same as previous comment.
same
source/DSCResources/DSC_SqlRole/DSC_SqlRole.psm1, line 589 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Same as previous comment.
same
tests/Unit/DSC_SqlRole.Tests.ps1, line 44 at r2 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
InModuleScope $script:dscResourceName {
InModuleScope
should only be insideBefore*
-/After*
-blocks andIt
-blocks. If they are not that code is run during discovery which we should avoid.See this:
- BeforeAll-block that uses InModuleScope to set script variables in the module's scope (that will be used by it-blocks' InModuleScope):
BeforeAll { - It-block that uses
InModuleScope
:
It 'Should return the correct values' { - It-block that uses
InModuleScope
with parameters:
It 'Should return the correct values' { - It-block that assert
Should -Invoke
(outsideInModuleScope
):
It 'Should return $true' {
working on it, just to let you know. And yes, a simple example would be appreciated.
Appreciate your help! 😃 I'm working on a blog post. I think I can push a draft later today. I will link to it then. 🙂 |
First draft. Didn't come as far as I hoped, but continue tomorrow. Hopefully it is to some help: https://github.com/dsccommunity/dsccommunity.org/blob/98c4e19b5356e6b3afccb488c3f90f10f90d01db/content/blog/convert-tests-to-pester5-for-dsc-community-repository.md |
Almost done, new draft here as the URL changes for each push: https://github.com/dsccommunity/dsccommunity.org/blob/75a808da985c3784358c521525d9e88d443f66d6/content/blog/convert-tests-to-pester5-for-dsc-community-repository.md |
5061fbc
to
9a5ae6a
Compare
Now the blog is posted https://dsccommunity.org/blog/convert-tests-to-pester5-for-dsc-community-repository/ |
9a5ae6a
to
4ccb37b
Compare
4ccb37b
to
f46efa3
Compare
7f7d166
to
11777ce
Compare
Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again. |
11777ce
to
4217060
Compare
de291b8
to
effafd9
Compare
11ae7a6
to
a5cca69
Compare
c0a0a7c
to
220b1f6
Compare
5eda223
to
946cb22
Compare
d26b276
to
16214ff
Compare
I'm closing this as they have now been converted in the PR dsccommunity#1550. |
Pull Request (PR) description
@johlju Two fixes for pester 3 dsccommunity#1550
This Pull Request (PR) fixes the following issues
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is