From 93199735d83449ef50303fb580bdb56625e8b140 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 27 Aug 2015 16:16:13 -0700 Subject: [PATCH] added unit test for getting the machine name from the p/invoke --- src/ps_test/test_CorePsPlatform.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 99a3d8f3f2..0f937df3b2 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -65,5 +65,29 @@ namespace PSTests Assert.Equal(username, Platform.NonWindowsGetUserName()); } } + + [Fact] + public static void TestGetMachineName() + { + var startInfo = new ProcessStartInfo + { + FileName = @"/usr/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()); + } + + + } } }