diff --git a/scripts/gen/SYS_AUTO/ParserStrings.cs b/scripts/gen/SYS_AUTO/ParserStrings.cs index 5735d3e3c..b8fe6662b 100644 --- a/scripts/gen/SYS_AUTO/ParserStrings.cs +++ b/scripts/gen/SYS_AUTO/ParserStrings.cs @@ -595,6 +595,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Failed to convert the value of CimProperty {0} to the property value of class {1}.. + /// + internal static string ConvertCimPropertyToObjectPropertyFailed { + get { + return ResourceManager.GetString("ConvertCimPropertyToObjectPropertyFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Could not get dispatch ID for {0} (error: {1}).. /// @@ -838,6 +847,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Keyword '{0}' already defined in the configuration.. + /// + internal static string DuplicateKeywordDefinition { + get { + return ResourceManager.GetString("DuplicateKeywordDefinition", resourceCulture); + } + } + /// /// Looks up a localized string similar to Duplicate named arguments '{0}' are not allowed.. /// @@ -1090,6 +1108,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Property {0} of PowerShell class {1} is not declared as array type, but defined in its configuration instance as instance array type.. + /// + internal static string ExpectArrayTypeOfPropertyInPSClass { + get { + return ResourceManager.GetString("ExpectArrayTypeOfPropertyInPSClass", resourceCulture); + } + } + /// /// Looks up a localized string similar to An expression was expected after '('.. /// @@ -1430,6 +1457,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Failed to create an object of PowerShell class {0}.. + /// + internal static string InstantiatePSClassObjectFailed { + get { + return ResourceManager.GetString("InstantiatePSClassObjectFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to '{0}': Interface name expected.. /// @@ -1538,6 +1574,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to The hashtable supplied to the Desired State Configuration resource {0} is not valid. The key or value cannot be null or empty.. + /// + internal static string InvalidHashtable { + get { + return ResourceManager.GetString("InvalidHashtable", resourceCulture); + } + } + /// /// Looks up a localized string similar to The member '{0}' is not valid. Valid members are ///'{1}'.. @@ -1602,6 +1647,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to The username supplied to the Desired State Configuration resource {0} is not valid. The username cannot be null or empty.. + /// + internal static string InvalidPassword { + get { + return ResourceManager.GetString("InvalidPassword", resourceCulture); + } + } + /// /// Looks up a localized string similar to The PowerShell data file '{0}' is invalid since it cannot be evaluated into a Hashtable object.. /// @@ -1665,6 +1719,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to The username supplied to the Desired State Configuration resource {0} is not valid. The username cannot be null or empty.. + /// + internal static string InvalidUserName { + get { + return ResourceManager.GetString("InvalidUserName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Expression is not allowed in a Using expression.. /// @@ -2925,6 +2988,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Property {0} is not declared in PowerShell class {1}, but defined in its configuration instance.. + /// + internal static string PropertyNotDeclaredInPSClass { + get { + return ResourceManager.GetString("PropertyNotDeclaredInPSClass", resourceCulture); + } + } + /// /// Looks up a localized string similar to The property '{0}' cannot be found on this object. Verify that the property exists and can be set.. /// diff --git a/scripts/gen/SYS_AUTO/ParserStrings.resources b/scripts/gen/SYS_AUTO/ParserStrings.resources index c0d703f77..7efbef9eb 100644 Binary files a/scripts/gen/SYS_AUTO/ParserStrings.resources and b/scripts/gen/SYS_AUTO/ParserStrings.resources differ diff --git a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs index 114fdf01b..c8eb48f79 100644 --- a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs +++ b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs @@ -250,6 +250,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Failed to find vmcompute.dll. The Hyper-V role may not be enabled on this machine.. + /// + internal static string CannotFindVmComputeDll { + get { + return ResourceManager.GetString("CannotFindVmComputeDll", resourceCulture); + } + } + /// /// Looks up a localized string similar to The call to Windows API GetStdHandle to get the Standard Error handle resulted in an error code: {0}.. /// @@ -538,6 +547,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Could not find the toolkit, '{0}'. The toolkit must be a file named '{1}' within a 'Toolkits' directory in a module in the current module path.. + /// + internal static string CouldNotFindToolkit { + get { + return ResourceManager.GetString("CouldNotFindToolkit", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} is not a valid value for the parameter {1}. The value must be greater than or equal to 0.. /// @@ -767,6 +785,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Could not parse visible command defintion for '{0}'. The visible command definition must be a hashtable with the keys of 'Name' and 'Parameters'. The value of the 'Parameters' key must be a collection of hashtables with the keys 'Name', and optionally either 'ValidateSet' or 'ValidatePattern'.. + /// + internal static string DISCCommandModificationSyntax { + get { + return ResourceManager.GetString("DISCCommandModificationSyntax", resourceCulture); + } + } + /// /// Looks up a localized string similar to Company associated with this session configuration. /// @@ -956,6 +983,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to User roles (security groups), and the additional configuration settings that should be applied to them. + /// + internal static string DISCRoleDefinitionsComment { + get { + return ResourceManager.GetString("DISCRoleDefinitionsComment", resourceCulture); + } + } + /// /// Looks up a localized string similar to Version number of the schema used for this configuration file. /// @@ -974,6 +1010,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Toolkits to apply to this session configuration. This toolkit must be defined as a session configuration file named after that toolkit within a 'Toolkits' directory in a module in the current module path.. + /// + internal static string DISCToolkitsToLoadComment { + get { + return ResourceManager.GetString("DISCToolkitsToLoadComment", resourceCulture); + } + } + /// /// Looks up a localized string similar to Specifies the transport options for this session configuration. /// @@ -1629,6 +1674,33 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to The 'Roles' entry must be a hashtable, but was a {0}.. + /// + internal static string InvalidRoleEntry { + get { + return ResourceManager.GetString("InvalidRoleEntry", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The key '{0}' is not valid in a toolkit or role definition.. + /// + internal static string InvalidRoleToolkitKey { + get { + return ResourceManager.GetString("InvalidRoleToolkitKey", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Could not convert the value of the '{0}' role entry to a hashtable. The 'Roles' entry must be a hashtable with group names for keys, where the value associated with each key is another hashtable of session configuration properties for that role.. + /// + internal static string InvalidRoleValue { + get { + return ResourceManager.GetString("InvalidRoleValue", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} is not a valid schema value. Valid values are "http" and "https".. /// @@ -3053,6 +3125,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Failed to create an instance of RemoteSessionHyperVSocketServer.. + /// + internal static string RemoteSessionHyperVSocketServerConstructorFailure { + get { + return ResourceManager.GetString("RemoteSessionHyperVSocketServerConstructorFailure", resourceCulture); + } + } + /// /// Looks up a localized string similar to Remote transport error: {0}. /// @@ -3837,6 +3918,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to WSMan Initialization failed with error code: {0}.. + /// + internal static string WSManInitFailed { + get { + return ResourceManager.GetString("WSManInitFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to The maximum number of WS-Man URI redirections to allow while connecting to a remote computer. /// diff --git a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources index 7b771f8a5..f3a113e04 100644 Binary files a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources and b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources differ diff --git a/src/monad b/src/monad index a1a05637e..8e014f44d 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit a1a05637ebc40bdbfef51f8435e8592587a4eb5d +Subproject commit 8e014f44d72765f086fe516e870602d5a476076e diff --git a/src/pester-tests/Test-Environment-Variables.Tests.ps1 b/src/pester-tests/Test-Environment-Variables.Tests.ps1 index 6bde8f289..4bf643ffe 100644 --- a/src/pester-tests/Test-Environment-Variables.Tests.ps1 +++ b/src/pester-tests/Test-Environment-Variables.Tests.ps1 @@ -1,15 +1,34 @@ Describe "Test-Environment-Variables" { - It "Should have environment variable" { + It "Should have environment variables" { Get-Item ENV: | Should Not BeNullOrEmpty } - It "Should be able to access the members of the environment variable in two ways" { - (Get-Item ENV:HOME).Value | Should be "/root" - (Get-Item ENV:HOSTNAME).Value | Should Not BeNullOrEmpty - (Get-Item ENV:PATH).Value | Should Not BeNullOrEmpty + It "Should have a nonempty PATH" { + $ENV:PATH | Should Not BeNullOrEmpty + } - (ls ENV:HOME).Value | Should be "/root" - (ls ENV:HOSTNAME).Value | Should Not BeNullOrEmpty - (ls ENV:PATH).Value | Should Not BeNullOrEmpty + It "Should contain /bin in the PATH" { + $ENV:PATH | Should Match "/bin" + } + + It "Should be able to access the members of the environment variable" { + $expected = /bin/bash -c "cd ~ && pwd" + + (Get-Item ENV:HOME).Value | Should Be $expected + } + + It "Should be able to set the environment variables" { + $expected = "this is a test environment variable" + { $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should Not Throw + + $ENV:TESTENVIRONMENTVARIABLE | Should Not BeNullOrEmpty + $ENV:TESTENVIRONMENTVARIABLE | Should Be $expected + + } + + It "Should have the correct HOSTNAME" { + $expected = /bin/hostname + + $ENV:HOSTNAME | Should Be $expected } } diff --git a/src/pester-tests/Test-Remove-Item.Tests.ps1 b/src/pester-tests/Test-Remove-Item.Tests.ps1 new file mode 100644 index 000000000..017a461d7 --- /dev/null +++ b/src/pester-tests/Test-Remove-Item.Tests.ps1 @@ -0,0 +1,139 @@ +Describe "Test-Remove-Item" { + $testpath = "/tmp/" + $testfile = "testfile.txt" + $testfilepath = $testpath + $testfile + Context "File removal Tests" { + BeforeEach { + New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force + + Test-Path $testfilepath | Should Be $true + + } + + It "Should be able to be called on a regular file without error using the Path switch" { + { Remove-Item -Path $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to be called on a file without the Path switch" { + { Remove-Item $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to call the rm alias" { + { rm $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to call the del alias" { + { del $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to call the erase alias" { + { erase $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to call the ri alias" { + { ri $testfilepath } | Should Not Throw + + Test-Path $testfilepath | Should Be $false + } + + It "Should not be able to remove a read-only document without using the force switch" { + # Set to read only + Set-ItemProperty -Path $testfilepath -Name IsReadOnly -Value $true + + # attempt to remove the file + { Remove-Item $testfilepath -ErrorAction SilentlyContinue } | Should Not Throw + + # validate + Test-Path $testfilepath | Should Be $true + + # remove using the -force switch on the readonly object + Remove-Item $testfilepath -Force + + # Validate + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to remove all files matching a regular expression with the include switch" { + # Create multiple files with specific string + New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum" + New-Item -Name file2.txt -Path $testpath -ItemType "file" -Value "lorem ipsum" + New-Item -Name file3.txt -Path $testpath -ItemType "file" -Value "lorem ipsum" + # Create a single file that does not match that string - already done in BeforeEach + + # Delete the specific string + Remove-Item /tmp/* -Include file*.txt + # validate that the string under test was deleted, and the nonmatching strings still exist + Test-path /tmp/file1.txt | Should Be $false + Test-path /tmp/file2.txt | Should Be $false + Test-path /tmp/file3.txt | Should Be $false + Test-Path $testfilepath | Should Be $true + + # Delete the non-matching strings + Remove-Item $testfilepath + + Test-Path $testfilepath | Should Be $false + } + + It "Should be able to not remove any files matching a regular expression with the exclude switch" { + # Create multiple files with specific string + New-Item -Name file1.wav -Path $testpath -ItemType "file" -Value "lorem ipsum" + New-Item -Name file2.wav -Path $testpath -ItemType "file" -Value "lorem ipsum" + + # Create a single file that does not match that string + New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum" + + # Delete the specific string + Remove-Item /tmp/file* -Exclude *.wav -Include *.txt + + # validate that the string under test was deleted, and the nonmatching strings still exist + Test-Path /tmp/file1.wav | Should Be $true + Test-Path /tmp/file2.wav | Should Be $true + Test-Path /tmp/file1.txt | Should Be $false + + # Delete the non-matching strings + Remove-Item /tmp/file1.wav + Remove-Item /tmp/file2.wav + + Test-Path /tmp/file1.wav | Should Be $false + Test-Path /tmp/file2.wav | Should Be $false + } + } + + Context "Directory Removal Tests" { + $testdirectory = "/tmp/testdir" + $testsubdirectory = $testdirectory + "/subd" + BeforeEach { + New-Item -Name "testdir" -Path "/tmp/" -ItemType "directory" -Force + + Test-Path $testdirectory | Should Be $true + } + + It "Should be able to remove a directory" { + { Remove-Item $testdirectory } | Should Not Throw + + Test-Path $testdirectory | Should Be $false + } + + It "Should be able to recursively delete subfolders" { + New-Item -Name "subd" -Path $testdirectory -ItemType "directory" + New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum" + + $complexDirectory = $testsubdirectory + "/" + $testfile + test-path $complexDirectory | Should Be $true + + { Remove-Item $testdirectory -Recurse} | Should Not Throw + + Test-Path $testdirectory | Should Be $false + } + } +} diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 99a3d8f3f..57e58bc32 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -65,5 +65,30 @@ namespace PSTests Assert.Equal(username, Platform.NonWindowsGetUserName()); } } + + [Fact] + public static void TestGetMachineName() + { + var startInfo = new ProcessStartInfo + { + FileName = @"/usr/bin/env", + Arguments = "hostname", + RedirectStandardOutput = true, + UseShellExecute = false + }; + using (Process process = Process.Start(startInfo)) + { + // Get output of call to hostname without trailing newline + string hostname = process.StandardOutput.ReadToEnd().Trim(); + process.WaitForExit(); + + // The process should return an exit code of 0 on success + Assert.Equal(0, process.ExitCode); + // It should be the same as what our platform code returns + Assert.Equal(hostname, Platform.NonWindowsGetMachineName()); + } + + + } } }