Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

Fiander
Copy link

@Fiander Fiander commented Dec 27, 2020

Pull Request (PR) description

@johlju Two fixes for pester 3 dsccommunity#1550

This Pull Request (PR) fixes the following issues

  • Fixes SqlRole
  • Fixes SqlTraceFlag

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju
Copy link
Owner

johlju commented Dec 27, 2020

Can you try to rebase the PR against my fork. In your local branch do:

git fetch origin f/support-pester-5
git rebase origin/f/support-pester-5

When everything looks okay, make sure your changes (commit) to the tests are still there, run

# This will overwrite the commits in the branch in your fork.
git push my --force

@Fiander
Copy link
Author

Fiander commented Dec 27, 2020

Was already trying to do that, but your example made it a lot simpler.
i sometimes get really confused with all the git therms

Copy link
Owner

@johlju johlju left a 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

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:

Copy link
Author

@Fiander Fiander left a 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 $mockErrorRecord.Exception.Message to "$($mockErrorRecord.Exception.Message)*"
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 inside Before*-/After*-blocks and It-blocks. If they are not that code is run during discovery which we should avoid.

See this:

working on it, just to let you know. And yes, a simple example would be appreciated.

@johlju
Copy link
Owner

johlju commented Dec 28, 2020

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. 🙂

@johlju
Copy link
Owner

johlju commented Dec 28, 2020

@johlju
Copy link
Owner

johlju commented Dec 29, 2020

@johlju johlju force-pushed the f/support-pester-5 branch 2 times, most recently from 5061fbc to 9a5ae6a Compare January 6, 2021 07:20
@johlju
Copy link
Owner

johlju commented Jan 8, 2021

Now the blog is posted https://dsccommunity.org/blog/convert-tests-to-pester5-for-dsc-community-repository/

@johlju johlju force-pushed the f/support-pester-5 branch from 9a5ae6a to 4ccb37b Compare January 12, 2021 11:04
@johlju johlju force-pushed the f/support-pester-5 branch from 4ccb37b to f46efa3 Compare January 27, 2021 17:44
@johlju johlju force-pushed the f/support-pester-5 branch 2 times, most recently from 7f7d166 to 11777ce Compare February 12, 2021 10:20
@github-actions
Copy link

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.

@johlju johlju force-pushed the f/support-pester-5 branch from 11777ce to 4217060 Compare March 11, 2021 15:08
@johlju johlju force-pushed the f/support-pester-5 branch from de291b8 to effafd9 Compare May 13, 2021 18:25
@johlju johlju force-pushed the f/support-pester-5 branch from 11ae7a6 to a5cca69 Compare September 4, 2021 16:44
@johlju johlju force-pushed the f/support-pester-5 branch from c0a0a7c to 220b1f6 Compare February 18, 2022 10:19
@johlju johlju force-pushed the f/support-pester-5 branch from 5eda223 to 946cb22 Compare March 9, 2022 15:50
@johlju johlju force-pushed the f/support-pester-5 branch from d26b276 to 16214ff Compare March 31, 2022 12:37
@johlju
Copy link
Owner

johlju commented Apr 14, 2022

I'm closing this as they have now been converted in the PR dsccommunity#1550.

@johlju johlju closed this Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants