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

Pester v5 migration #815

Merged
merged 5 commits into from Oct 3, 2021
Merged

Conversation

ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Oct 2, 2021

PR Summary

Fix #478

Converted to pester v5 tests syntax and v5.3.0 module version.

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Change is not breaking
  • This PR is ready to merge and is not Work in Progress
  • Code changes
    • Have unit tests created/ updated
    • Link to a filed issue
    • Change log has been updated with change under unreleased section

@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Oct 2, 2021

Currently The ConstrainedLanguage tests from tests\PSRule.Tests\PSRule.Common.Tests are failing locally. Not sure whats happened since they work in Pester v4.10.1. Can't really reproduce error locally either since no exception is thrown.

The error log:

Should fail
[-] Invoke-PSRule.With constrained language.Should fail to execute blocked code 158ms (143ms|15ms)
 at { $Null = $testObject | Invoke-PSRule -Path $ruleFilePath -Name 'ConstrainedTest2' -Option $option -ErrorAction Stop } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.';, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:828
 at <ScriptBlock>, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:828
 Expected an exception, with message 'Cannot invoke method. Method invocation is supported only on core types in this language mode.' to be thrown, but no exception was thrown.
Should fail
[-] Test-PSRuleTarget.With constrained language.Should fail to execute blocked code 97ms (89ms|8ms)
 at { $Null = $testObject | Test-PSRuleTarget -Path $ruleFilePath -Name 'ConstrainedTest2' -Option $option -ErrorAction Stop } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.';, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1112
 at <ScriptBlock>, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1112
 Expected an exception, with message 'Cannot invoke method. Method invocation is supported only on core types in this language mode.' to be thrown, but no exception was thrown.
Should fail
[-] Assert-PSRule.With constrained language.Should fail to execute blocked code 83ms (81ms|2ms)
 at { $Null = $testObject | Assert-PSRule -Path $ruleFilePath -Name 'ConstrainedTest2' -Option $option -ErrorAction Stop 6>&1 } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.';, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1369
 at <ScriptBlock>, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1369
 Expected an exception, with message 'Cannot invoke method. Method invocation is supported only on core types in this language mode.' to be thrown, but no exception was thrown.
WARNING: Using invariant culture may cause rule infomation to be displayed incorrectly. Consider using -Culture or set the Output.Culture option.
Should fail
[-] Get-PSRule.With constrained language.Should fail to execute blocked code 84ms (82ms|2ms)
 at { $Null = Get-PSRule -Path (Join-Path -Path $here -ChildPath 'UnconstrainedFile.Rule.ps1') -Name 'UnconstrainedFile1' -Option @{ 'execution.mode' = 'ConstrainedLanguage' } -ErrorAction Stop } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.';, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1817
 at <ScriptBlock>, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1817
 Expected an exception, with message 'Cannot invoke method. Method invocation is supported only on core types in this language mode.' to be thrown, but no exception was thrown.
Should fail
[-] Get-PSRuleHelp.With constrained language.Should fail to execute blocked code 58ms (56ms|2ms)
 at { $Null = Get-PSRuleHelp -Path (Join-Path -Path $here -ChildPath 'UnconstrainedFile.Rule.ps1') -Name 'UnconstrainedFile1' -Option @{ 'execution.mode' = 'ConstrainedLanguage' } -ErrorAction Stop } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.';, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1959
 at <ScriptBlock>, C:\Users\armcleod\Documents\github-repos\PSRule\tests\PSRule.Tests\PSRule.Common.Tests.ps1:1959
 Expected an exception, with message 'Cannot invoke method. Method invocation is supported only on core types in this language mode.' to be thrown, but no exception was thrown.

@BernieWhite If needed I can track this in a issue 🙂.

Definetely seems Pester v5 related, will see if I can figure it out.

@BernieWhite
Copy link
Member

@ArmaanMcleod Constrained language is when PowerShell is operating in a locked down environment. These failures check language is limited in these environments. The check is mocked for pester 4 tests, probably double check that is working.

@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Oct 2, 2021

@BernieWhite Yeah knew it was something small. I forgot to move the mocks into BeforeAll for those tests.

Thanks for spotting that, needed an extra pair of eyes since the tests all start looking the same after a while when doing these migrations😄 .

In any case I've learnt what ConstrainedLanguage does, thanks for explanation mate 🙂 .

@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review October 2, 2021 13:10
@ArmaanMcleod ArmaanMcleod requested a review from a team as a code owner October 2, 2021 13:10
Copy link
Member

@BernieWhite BernieWhite left a comment

Choose a reason for hiding this comment

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

@ArmaanMcleod Great work! All good to merge.

@ArmaanMcleod ArmaanMcleod merged commit 72f98c5 into microsoft:main Oct 3, 2021
@ArmaanMcleod ArmaanMcleod deleted the pester-v5-migration branch October 3, 2021 04:53
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.

Update CI pipeline to use Pester v5
2 participants