Skip to content

Conversation

@pougetat
Copy link

@pougetat pougetat commented Apr 2, 2019

PR Summary

This PR adds approx 50 tests (+3 seconds when running locally) for the remove-module cmdlet.

If anyone has suggestions for test cases I missed please feel free to comment. Some of the cases listed are quite vague for the moment. My objective is to optimize the number of tests written / branches tested. I will also screenshot some codeCov results once I get around to running it on the codebase.

Tests have been added tests for :

  • Remove-Module -Name
    • simple module name (single, multiple, repeated)
    • regular expressions (single, multiple, no matches) ["*" case breaks Pester (see code comment)]
    • error cases (no matches for simple names)
  • Remove-Module -FullyQualifiedName
    • using ModuleVersion
    • using RequiredVersion
    • error cases (no matches for names and versions)
  • Remove-Module -ModuleInfo
  • Remove-Module with constant module
    • with -Force
    • without -Force
  • Remove-Module with readonly module
    • with -Force
    • without -Force
      • with constant engine module (I don't actually know how to hit this code path since these modules aren't visible in the first place via Get-Module)
      • without constant engine module
  • Remove-Module with module providing current session drive
  • Remove-Module containing nested modules
    • simple dependency A -> B
    • circular dependency A -> A
  • Remove-Module required by other modules which are also imported
    • A -> B : remove B then A
    • A -> B : remove A then B

PR Context

This PR is aimed at increasing testing coverage for the module related cmdlets which we would like to refactor down the line.
This issue tracks the refactoring work : #8936

PR Checklist

@pougetat
Copy link
Author

pougetat commented Apr 2, 2019

Not too sure why this is is failing for Remove-Module -Name tests when eveything works locally (running just this test locally and no others):

    BeforeEach {
        Import-Module -Name "$testdrive\Modules\Foo\Foo.psd1" -Force
        Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force
        Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force

        (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo"
    }

With the following error :

Expected exactly @('Bar', 'Baz', 'Foo'), but got @('Bar', 'Baz', 'Foo', 'Foo').
53:         (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo"

For some reason 'Foo' appears twice.

@pougetat
Copy link
Author

pougetat commented Apr 3, 2019

Fixed the CI tests though I'm still not sure why I had two modules named "Foo" in my environment.
My initial thought was that it could be another Pester test that did not clean up its imported modules thus leaving a Foo module present but perhaps Pester tests are sandboxed in some way and these kinds of race conditions aren't possible.
Thoughts ?

@iSazonov iSazonov added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Apr 4, 2019
@pougetat pougetat changed the title Adding tests for remove-module [WIP] Adding tests for remove-module Apr 4, 2019
Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force
Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force

(Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure that it does that we expect. I suggest join strings and compare.
So all tests should be refactored.

Also please remove the line - all "Should" should be in "It" blocks.

Copy link
Author

@pougetat pougetat Apr 4, 2019

Choose a reason for hiding this comment

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

Addressed the second comment.

In regards to the first comment I can confirm that -BeExactly does indeed do what we expect to, at least in the sense that it makes sure that the list of modules we try to get are indeed present (both lists are equal).

@pougetat pougetat changed the title [WIP] Adding tests for remove-module Adding tests for remove-module Apr 5, 2019
@rjmholt rjmholt requested a review from daxian-dbw April 11, 2019 22:13
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM with one minor comment.

@adityapatwardhan adityapatwardhan changed the title Adding tests for remove-module Adding tests for remove-module Apr 22, 2019
@adityapatwardhan adityapatwardhan changed the title Adding tests for remove-module Adding tests for Remove-Module Apr 22, 2019
@adityapatwardhan adityapatwardhan merged commit 0bd9377 into PowerShell:master Apr 22, 2019
@iSazonov
Copy link
Collaborator

@pougetat Thanks for your contribution!

@fMichaleczek
Copy link
Contributor

@pougetat great job ! The only missing scenario is when you import module with using scripting.Classes.using.tests.ps1#L504 )

@rjmholt
Copy link
Collaborator

rjmholt commented Apr 23, 2019

@fMichaleczek Please feel free to contribute more tests

@fMichaleczek
Copy link
Contributor

@rjmholt sure ! if i write a test that failed (bug in powershell), what I should do with this test ?

@rjmholt
Copy link
Collaborator

rjmholt commented Apr 23, 2019

The ideal I think is to open a PR with the test marked as -Pending, so that when the behaviour changes the test passes.

TravisEz13 added a commit that referenced this pull request Apr 27, 2019
* return correct casing of filesystem path during normalization

* handle UNC case

* handle case to add trailing separator back

* add support for NTFS streams syntax

* add case-sensitive test

* only apply correct casing to directories

* handle 8.3 path syntax

* fix short path processing

* Remove elements which do not work on earlier version on Windows PowerShell (#9411)

* Use `Environment.NewLine` for new lines in `ConsoleHost` code (#9392)

* Run CodeFormatter for Eventing (#9394)

* Run CodeFormatter for MarkdownRender (#9398)

* Run CodeFormatter for Security module (#9399)

* Run CodeFormatter for WSMan.Runtime (#9401)

* Run CodeFormatter for WSMan.Management (#9400)

* Allow CI to run on branches with this name pattern: feature* (#9415)

* Run CodeFormatter with BraceNewLine,UsingLocation,FormatDocument,NewLineAbove rules (#9393)

* Build(deps): Bump NJsonSchema from 9.13.30 to 9.13.34 (#9421)

* Build(deps): Bump NJsonSchema from 9.13.34 to 9.13.35 (#9429)

Bumps [NJsonSchema](https://github.com/rsuter/NJsonSchema) from 9.13.34 to 9.13.35.
- [Release notes](https://github.com/rsuter/NJsonSchema/releases)
- [Commits](https://github.com/rsuter/NJsonSchema/commits)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Build(deps): Bump Newtonsoft.Json (#9431)

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 12.0.1 to 12.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](JamesNK/Newtonsoft.Json@12.0.1...12.0.2)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Build(deps): Bump Newtonsoft.Json from 12.0.1 to 12.0.2 (#9434)

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 12.0.1 to 12.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](JamesNK/Newtonsoft.Json@12.0.1...12.0.2)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Add Preview assets for msix (#9375)

* Adding tests for `Remove-Module` (#9276)

* Build(deps): Bump gulp from 4.0.0 to 4.0.1 in /test/common/markdown (#9441)

* Move warning message to EndProcessing so it only shows up once (#9385)

* Run Codeformatter for SMA (#9402)

* Fix the failed test and update 'Publish-TestResults' to make AzDO fail the task when any tests failed (#9457)

* Enable building on Kali Linux (#9471)

* Build test packages for windows, linux-x64, linux-arm, linux-arm64 and macOS (#9476)

* Build(deps): Bump NJsonSchema from 9.13.35 to 9.13.36 (#9478)

* Update Release_Process.md

Add item for global tool


Co-authored-by: Steve Lee <slee@microsoft.com>
Co-authored-by: Steve Lee (POWERSHELL) <slee@ntdev.microsoft.com>
Co-authored-by: Aditya Patwardhan <adityap@microsoft.com>
Co-authored-by: Ilya <darpa@yandex.ru>
Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
Co-authored-by: null <dependabot[bot]@users.noreply.github.com>
Co-authored-by: pougetat <thomas.pouget-abadie@ensimag.grenoble-inp.fr>
Co-authored-by: Andrew <anmenaga@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Test Indicates that a PR should be marked as a test change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants