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

Clean xScript resource and add tests #290

Merged
merged 1 commit into from
Dec 8, 2016

Conversation

kwirkykat
Copy link
Contributor

@kwirkykat kwirkykat commented Dec 6, 2016

This is the cleaned xScript resource for #160.

Unit and integration tests have been added and the documentation for xScript has been updated accordingly.

I also just moved the xWindowsFeature section in the README to where it should be alphabetically in the list since it was originally where Script should go.

This PR contains a change that is also included in #289 which is the Get-AppVeyorAdministrator credential in the CommonTestHelper. I will rebase and resolve the conflict after one of these two PRs is merged.

@mbreakey3 and/or @TravisEz13 Please review.


This change is Reviewable

@kwirkykat kwirkykat added the needs review The pull request needs a code review. label Dec 6, 2016
[CmdletBinding()]
param ()

if ($null -eq $script:appVeyorAdministratorCredential)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set-StrictMode -Version latest is not on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TravisEz13 It's turned on in #289 where I made the main changes to the CommonTestHelper. You can see it is included on this line for the changes included in that PR. This exact same function is there and passes StrictMode.

I did not want to include all the changes to the CommonTestHelper here. I only included Get-AppVeyorAdministratorCredential here because it is needed to get a valid credential to test running a script under.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, this will break when they merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the variable initialization

@kwirkykat kwirkykat force-pushed the CleanScript branch 2 times, most recently from 5d12962 to 03aeb98 Compare December 7, 2016 01:23
@mbreakey3
Copy link
Contributor

Reviewed 8 of 11 files at r1, 3 of 3 files at r2.
Review status: all files reviewed at latest revision, 18 unresolved discussions.


README.md, line 230 at r2 (raw file):

* **[String] GetScript** _(Key)_: A string that can be used to create a PowerShell script block that retrieves the current state of the resource. This script block runs when the Get-DscConfiguration cmdlet is called. This script block should return a hash table containing one key named Result with a string value.
* **[String] SetScript** _(Key)_: A string that can be used to create PowerShell script block that sets the resource to the desired state. This script block runs conditionally when the Start-DscConfiguration cmdlet is called. The TestScript  script block will run first. If the TestScript block returns False, this script block will run. If the TestScript block returns True, this script block will not run. This script block should not return.

'A string that can be used to create a PowerShell script block...'
Also, is there an extra space between 'The TestScript' and 'script block will run first.' ? It's hard to tell.


DSCResources/MSFT_xScriptResource/MSFT_xScriptResource.psm1, line 210 at r2 (raw file):

    $invokeScriptResult = Invoke-Script @invokeScriptParameters

    # If the script is returing multiple objects, then we consider the last object to be the result of script execution.

'...result of the script execution.'


DSCResources/MSFT_xScriptResource/MSFT_xScriptResource.schema.mof, line 6 at r2 (raw file):

{
  [Key, Description("A string that can be used to create a PowerShell script block that retrieves the current state of the resource.")] String GetScript;
  [Key, Description("A string that can be used to create PowerShell script block that sets the resource to the desired state.")] String SetScript;

'..to create a PowerShell script block..'


DSCResources/MSFT_xScriptResource/en-US/MSFT_xScriptResource.schema.mfl, line 5 at r2 (raw file):

{
    [Key,Description("A string that can be used to create a PowerShell script block that retrieves the current state of the resource.") : Amended] String GetScript;
    [Key,Description("A string that can be used to create PowerShell script block that sets the resource to the desired state.") : Amended] String SetScript;

'...to create a PowerShell script block...'


Tests/CommonTestHelper.psm1, line 784 at r2 (raw file):

    if ($null -eq $script:appVeyorAdministratorCredential)
    {
        $randomObj = New-Object System.Random
New-Object -TypeName System.Random

Tests/CommonTestHelper.psm1, line 785 at r2 (raw file):

    {
        $randomObj = New-Object System.Random
        $password = ""

single quotes


Tests/CommonTestHelper.psm1, line 786 at r2 (raw file):

        $randomObj = New-Object System.Random
        $password = ""
        1..(Get-Random -Minimum 15 -Maximum 126) | ForEach { $password = $password + [char]$randomObj.next(45,126) }

[Char]


Tests/CommonTestHelper.psm1, line 793 at r2 (raw file):

        $objUser = [ADSI]("WinNT://$($env:computerName)/$username")
        $null = $objUser.SetPassword($password)
        [Microsoft.Win32.Registry]::SetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", $password)

single quotes


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 44 at r2 (raw file):

        }

        Context 'Get, set, and test scripts specified and Credential not specified' {

'Get, Set, and Test...'


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 70 at r2 (raw file):

            }

            It 'Should have created test file' {

'Should have created the test file'


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 79 at r2 (raw file):

        }

        Context 'Get, set, and test scripts specified and Credential specified' {

'Get, Set, Test..'


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 116 at r2 (raw file):

            }

            It 'Should have created test file' {

'...the test file'


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 1 at r2 (raw file):

# All tests with credentials will be skipped

It doesn't look like these are being skipped anymore


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 22 at r2 (raw file):

        $secureTestPassword = ConvertTo-SecureString -String $testPassword -AsPlainText -Force

        $script:testCredenital = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList @( $testUsername, $secureTestPassword)

no space needed between '@(' and '$testUsername'. Or, add a space before the last parenthesis


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 90 at r2 (raw file):

                    $null = Get-TargetResource @getTargetResourceParameters
                    Assert-MockCalled -CommandName 'Invoke-Script' -ParameterFilter { $null -eq (Compare-Object -ReferenceObject $expectedScriptBlock.Ast -DifferenceObject $ScriptBlock.Ast) } -Times 1 -Scope 'It'

I know it's kind of a pain, but can you break up the 'Assert-MockCalled lines'


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 283 at r2 (raw file):

            Mock -CommandName 'Invoke-Script' -MockWith { return @( (-not $expectedBoolean), $expectedBoolean ) }

            Context 'Specified get script returns multiple booleans' {

'Specified test script'


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 309 at r2 (raw file):

            Mock -CommandName 'Invoke-Script' -MockWith { return 'Value1' }

            Context 'Specified get script returns a string' {

'Specified test script...'


Comments from Reviewable

@mbreakey3 mbreakey3 added waiting for author response The pull request is waiting for the author to respond to comments in the pull request. and removed needs review The pull request needs a code review. labels Dec 7, 2016
@kwirkykat
Copy link
Contributor Author

Review status: 4 of 11 files reviewed at latest revision, 18 unresolved discussions.


README.md, line 230 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'A string that can be used to create a PowerShell script block...'
Also, is there an extra space between 'The TestScript' and 'script block will run first.' ? It's hard to tell.

Done.


DSCResources/MSFT_xScriptResource/MSFT_xScriptResource.psm1, line 210 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'...result of the script execution.'

Done.


DSCResources/MSFT_xScriptResource/MSFT_xScriptResource.schema.mof, line 6 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'..to create a PowerShell script block..'

Done.


DSCResources/MSFT_xScriptResource/en-US/MSFT_xScriptResource.schema.mfl, line 5 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'...to create a PowerShell script block...'

Done.


Tests/CommonTestHelper.psm1, line 784 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…
New-Object -TypeName System.Random

Done.


Tests/CommonTestHelper.psm1, line 785 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

single quotes

Done.


Tests/CommonTestHelper.psm1, line 786 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

[Char]

Done.


Tests/CommonTestHelper.psm1, line 793 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

single quotes

Done.


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 44 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'Get, Set, and Test...'

I prefer them as lower-case adjectives here.


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 70 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'Should have created the test file'

Done.


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 79 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'Get, Set, Test..'

I prefer them as lower-case adjectives here.


Tests/Integration/MSFT_xScriptResource.Integration.Tests.ps1, line 116 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'...the test file'

Done.


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 1 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

It doesn't look like these are being skipped anymore

Done.


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 22 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

no space needed between '@(' and '$testUsername'. Or, add a space before the last parenthesis

Done.


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 90 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

I know it's kind of a pain, but can you break up the 'Assert-MockCalled lines'

Done.


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 283 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'Specified test script'

Done.


Tests/Unit/MSFT_xScriptResource.Tests.ps1, line 309 at r2 (raw file):

Previously, mbreakey3 (Mariah) wrote…

'Specified test script...'

Done.


Comments from Reviewable

@kwirkykat kwirkykat added needs review The pull request needs a code review. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Dec 8, 2016
@mbreakey3
Copy link
Contributor

Reviewed 7 of 7 files at r3.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@mbreakey3
Copy link
Contributor

:lgtm:


Review status: 10 of 11 files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@mbreakey3 mbreakey3 merged commit b4c1191 into dsccommunity:dev Dec 8, 2016
@vors vors removed the needs review The pull request needs a code review. label Dec 8, 2016
@kwirkykat kwirkykat deleted the CleanScript branch December 8, 2016 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants