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

Remove unnecessary path split in FileSystemProvider.CreateDirectory #24615

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tadas
Copy link
Contributor

@Tadas Tadas commented Nov 23, 2024

PR Summary

Remove unnecessary path split in FileSystemProvider.CreateDirectory because those parts are not used anywhere and ultimately end up being combined again for the Directory.CreateDirectory call.

PR Context

Fixes pester/Pester#2258 :

When invoking the New-Item cmdlet with a path of TestDrive:\ -Force during a test, a new folder in the current working directory with the name of the guid of the TestDrive: provider is created.

PR Checklist

@Tadas Tadas requested a review from anmenaga as a code owner November 23, 2024 18:32
@@ -1172,6 +1172,11 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature
$result.Name | Should -BeExactly $testDir
}

It "Verify Provider Root Directory + Force" {
$result = New-Item -Path . -ItemType Directory -Force
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test is passed without the fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm not sure why would it fail for me then

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Debian GNU/Linux 12 (bookworm)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> Invoke-Pester ./test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 -Name "Extended FileSystem Item/Content Cmdlet Provider Tests"

Starting discovery in 1 files.
Discovery found 154 tests in 59ms.
Running tests.
What if: Performing the operation "Create Directory" on target "Destination: /tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/testDir".
[-] Extended FileSystem Item/Content Cmdlet Provider Tests.Valdiate New-Item parameters.Verify Provider Root Directory + Force 14ms (13ms|1ms)
Expected strings to be the same, but they were different.
Expected length: 41
Actual length:   48
Strings differ at index 1.
Expected: '/tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047'
But was:  '/home/tadas/0abd470a-0b42-49b3-8f36-4bb90f4b5047'
-^
at $result.FullName.TrimEnd('/\') | Should -BeExactly "$TestDrive", /home/tadas/Dev/PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1:1177
at <ScriptBlock>, /home/tadas/Dev/PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1:1177
What if: Performing the operation "Move File" on target "Item: /tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/testFile.txt Destination: /tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/movedFile.txt".
What if: Performing the operation "Rename File" on target "Item: /tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/testFile.txt Destination: /tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/NewName.txt".
What if: Performing the operation "Remove File" on target "/tmp/0abd470a-0b42-49b3-8f36-4bb90f4b5047/testFile.txt".
What if: Performing the operation "Set Content" on target "Path: TestDrive:/testFile.txt".
Tests completed in 723ms
Tests Passed: 40, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 113

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be clear, I run the command in regular session (not in Pester) and it works well. So, it is a question what scenario you are trying to fix.

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.

TestDrive:\ provided to New-Item creates folder in current working directory
2 participants