added unit test for getting the machine name from the p/invoke

This commit is contained in:
Zachary Folwick 2015-08-27 16:16:13 -07:00 committed by Andrew Schwartzmeyer
parent e68785ea26
commit 93199735d8

View file

@ -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());
}
}
}
}