ps/Modules/Alkami.PowerShell.Common/Public/Get-UncPath.tests.ps1
2023-05-30 22:51:22 -07:00

69 lines
2.8 KiB
PowerShell

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "Get-UncPath" {
Context "Returns Correct Values" {
It "Should Have Correct C:/ Drive UNC Directory Path" {
$result = Get-UncPath -filePath "C:/temp/test/path" -ComputerName "FAKE1234"
$result | should -BeExactly "\\FAKE1234\C$\temp\test\path"
}
It "Should Have Correct D:/ Drive UNC Directory Path" {
$result = Get-UncPath -filePath "D:/temp/test/path" -ComputerName "FAKE1234"
$result | should -BeExactly "\\FAKE1234\D$\temp\test\path"
}
It "Should Have Correct C:/ Drive UNC File Path" {
$result = Get-UncPath -filePath "C:/temp/test/path/file.txt" -ComputerName "FAKE1234"
$result | should -BeExactly "\\FAKE1234\C$\temp\test\path\file.txt"
}
It "Should Have Correct D:/ Drive UNC File Path" {
$result = Get-UncPath -filePath "D:/temp/test/path/file.txt" -ComputerName "FAKE1234"
$result | should -BeExactly "\\FAKE1234\D$\temp\test\path\file.txt"
}
}
Context "Handles Local UNC Pathing Ignore Flag" {
It "Should Have UNC Path to Local Machine Without Flag" {
$result = Get-UncPath -filePath "D:/temp/test/path/file.txt" -ComputerName ($env:COMPUTERNAME)
$result | should -BeExactly "\\$env:COMPUTERNAME\D$\temp\test\path\file.txt"
}
It "Should Have Correct localhost Path" {
$filepath = "C:/temp/test/path/file.txt";
$result = Get-UncPath -filePath $filepath -ComputerName "localhost" -IgnoreLocalPaths
$result | should -BeExactly $filepath;
}
It "Should Have Correct ComputerName Path" {
$filepath = "C:/temp/test/path/file.txt";
$result = Get-UncPath -filePath $filepath -ComputerName ($env:COMPUTERNAME) -IgnoreLocalPaths
$result | should -BeExactly $filepath;
}
It "Should Have Correct FQDN Path" {
$filepath = "C:/temp/test/path/file.txt";
$result = Get-UncPath -filePath $filepath -ComputerName (Get-FullyQualifiedServerName) -IgnoreLocalPaths
$result | should -BeExactly $filepath;
}
It "Should Return UNC Path for Non-Local Machine" {
$filepath = "C:/temp/test/path/file.txt";
$result = Get-UncPath -filePath $filepath -ComputerName "FAKE1234" -IgnoreLocalPaths
$result | should -BeExactly "\\FAKE1234\C$\temp\test\path\file.txt";
}
}
}