mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Cleanup NonWindowsGetDomainName() (#6948)
Add an optional extended description…
This commit is contained in:
@@ -545,22 +545,6 @@ namespace System.Management.Automation
|
||||
return Unix.NativeMethods.SetDate(&tm) == 0;
|
||||
}
|
||||
|
||||
internal static string NonWindowsGetDomainName()
|
||||
{
|
||||
string name = Unix.NativeMethods.GetFullyQualifiedName();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
// name is hostname.domainname, so extract domainname
|
||||
int index = name.IndexOf('.');
|
||||
if (index >= 0)
|
||||
{
|
||||
return name.Substring(index + 1);
|
||||
}
|
||||
}
|
||||
// if the domain name could not be found, do not throw, just return empty
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// Hostname in this context seems to be the FQDN
|
||||
internal static string NonWindowsGetHostName()
|
||||
{
|
||||
|
||||
@@ -86,29 +86,6 @@ namespace PSTests.Parallel
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestGetDomainName()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = @"/usr/bin/env",
|
||||
Arguments = "dnsdomainname",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
using (Process process = Process.Start(startInfo))
|
||||
{
|
||||
// Get output of call to hostname without trailing newline
|
||||
string domainName = 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(domainName, Platform.NonWindowsGetDomainName());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestIsExecutable()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user