Skip to content
Prev Previous commit
Next Next commit
[feature] remove drive after test
  • Loading branch information
kwkam committed Mar 10, 2018
commit d7d18d916c2542e8e45a5a8d5accf958a8be21eb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
Describe "Resolve-Path returns proper path" -Tag "CI" {
BeforeAll {
$driveName = "RvpaTest"
$root = Join-Path $TestDrive "fakeroot"
$file = Join-Path $root "file.txt"
$null = New-Item -Path $root -ItemType Directory -Force
$null = New-Item -Path $file -ItemType File -Force
$null = New-PSDrive -Name $driveName -PSProvider FileSystem -Root $root

$testRoot = Join-Path $TestDrive ""
$fakeRoot = Join-Path "$driveName`:" ""

$relCases = @(
@{ wd = $fakeRoot; target = $testRoot; expected = $testRoot }
@{ wd = $testRoot; target = Join-Path $fakeRoot "file.txt"; expected = Join-Path "." "fakeroot" "file.txt" }
)
}
AfterAll {
Remove-PSDrive -Name $driveName -PSProvider FileSystem
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

-PSProvider FileSystem is unnecessary

}
It "Resolve-Path returns resolved paths" {
Resolve-Path $TESTDRIVE | Should be "$TESTDRIVE"
}
Expand All @@ -23,28 +42,11 @@ Describe "Resolve-Path returns proper path" -Tag "CI" {
$result = Resolve-Path -LiteralPath "TestDrive:\\\\\"
($result.Path.TrimEnd('/\')) | Should Be "TestDrive:"
}
It "Resolve-Path -Relative should return correct path on different drive" {
$base = Join-Path $TestDrive "ResolvePath.relative"
$root = Join-Path $base "fakeroot"
$file = Join-Path $root "file.txt"
$expectedFilePath = Join-Path "." "fakeroot" "file.txt"
$driveName = "RvpaTest"
$null = New-Item -Path $base -ItemType Directory -Force
$null = New-Item -Path $root -ItemType Directory -Force
$null = New-Item -Path $file -ItemType File -Force
$null = New-PSDrive -Name $driveName -PSProvider FileSystem -Root $root
$driveRoot = Join-Path "$driveName`:" ""
$driveFile = Join-Path "$driveName`:" "file.txt"
try {
Push-Location -Path $driveRoot
Resolve-Path -Path $base -Relative | Should BeExactly $base
}
finally {
Pop-Location
}
It "Resolve-Path -Relative should return correct path on different drive" -TestCases $relCases {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a item for test name in $relCases which can be used in the It. Otherwise, all the variations have the same name in the log file.

It "Resolve-Path -Relative should return correct path on different drive - " -TestCases $relCases

param($wd, $target, $expected)
try {
Push-Location -Path $base
Resolve-Path -Path $driveFile -Relative | Should BeExactly $expectedFilePath
Push-Location -Path $wd
Resolve-Path -Path $target -Relative | Should BeExactly $expected
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use new syntax Should -BeExactly.

}
finally {
Pop-Location
Expand Down