mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
* Test fixes and changes needed to support Pester 4.0.8 * Replace 'Should Contain' with new 'Should FileContentMatch' assertion Explicitly check for string creation with write-output * Use the current version of pester and install it in modulesDir * Simplify logic for relative path test. Multiple '..' is not needed for a relative path, a single one will do. Also, on multi-drive systems using split-path -noqualifier will probably do the wrong thing with regard to constructing a correct path. Remove extraneous Should Not Throw test, if this throws, the test will fail, we don't need to explicitly assert the not throw * In some environments it is possible that computer name is 'localhost', so that should be allowed * [feature] Add link for migrating tests from Pester v3 to v4 Fix up capitalization and white space issues Change one test to check FullyQualifiedErrorId rather than just `Should Throw` * [feature] update invoke-item test to handle the case where multiple notepad processes are running * Fix spelling issue with Pester 4x, calling it Pester 4 should be sufficient
74 lines
2.2 KiB
PowerShell
74 lines
2.2 KiB
PowerShell
Describe "ConvertFrom-StringData DRT Unit Tests" -Tags "CI" {
|
|
It "Should able to throw error when convert invalid line" {
|
|
$str =@"
|
|
#comments here
|
|
abc
|
|
#comments here
|
|
def=content of def
|
|
"@
|
|
try
|
|
{
|
|
ConvertFrom-StringData $str
|
|
Throw "we expect 'InvalidOperation' exception"
|
|
}
|
|
catch
|
|
{
|
|
$_.FullyQualifiedErrorId | Should be "InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand"
|
|
}
|
|
}
|
|
}
|
|
|
|
Describe "ConvertFrom-StringData" -Tags "CI" {
|
|
$sampleData = @'
|
|
foo = 0
|
|
bar = 1
|
|
bazz = 2
|
|
'@
|
|
|
|
It "Should not throw when called with just the stringdata switch" {
|
|
{ ConvertFrom-StringData -StringData 'a=b' } | Should Not Throw
|
|
}
|
|
|
|
It "Should return a hashtable" {
|
|
$result = ConvertFrom-StringData -StringData 'a=b'
|
|
$result | Should BeOfType Hashtable
|
|
}
|
|
|
|
It "Should throw if not in x=y format" {
|
|
{ ConvertFrom-StringData -StringData 'ab' } | Should Throw
|
|
{ ConvertFrom-StringData -StringData 'a,b' } | Should Throw
|
|
{ ConvertFrom-StringData -StringData 'a b' } | Should Throw
|
|
{ ConvertFrom-StringData -StringData 'a\tb' } | Should Throw
|
|
{ ConvertFrom-StringData -StringData 'a:b' } | Should Throw
|
|
}
|
|
|
|
It "Should return the data on the left side in the key" {
|
|
$actualValue = ConvertFrom-StringData -StringData 'a=b'
|
|
|
|
$actualValue.Keys | Should Be "a"
|
|
}
|
|
|
|
It "Should return the data on the right side in the value" {
|
|
$actualValue = ConvertFrom-StringData -StringData 'a=b'
|
|
|
|
$actualValue.Values | Should Be "b"
|
|
}
|
|
|
|
It "Should return a keycollection for the keys" {
|
|
$(ConvertFrom-StringData -StringData 'a=b').Keys.PSObject.TypeNames[0] | Should Be "System.Collections.Hashtable+KeyCollection"
|
|
}
|
|
|
|
It "Should return a valuecollection for the values" {
|
|
$(ConvertFrom-StringData -StringData 'a=b').Values.PSObject.TypeNames[0] | Should Be "System.Collections.Hashtable+ValueCollection"
|
|
}
|
|
|
|
It "Should work for multiple lines" {
|
|
{ ConvertFrom-StringData -StringData $sampleData } | Should Not Throw
|
|
|
|
# keys are not order guaranteed
|
|
$(ConvertFrom-StringData -StringData $sampleData).Keys | Should BeIn @("foo", "bar", "bazz")
|
|
|
|
$(ConvertFrom-StringData -StringData $sampleData).Values | Should BeIn @("0","1","2")
|
|
}
|
|
}
|