Commit 9cc22a7f authored by Alex Brainman's avatar Alex Brainman

net: skip TestInterfacesWithNetsh if "netsh help" contains no English words

Fixes #14859

Change-Id: I262d634ee22498ec9855d273afdd409149765294
Reviewed-on: https://go-review.googlesource.com/21195Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c12a0e64
......@@ -178,18 +178,6 @@ func isWindowsXP(t *testing.T) bool {
return major < 6
}
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetACP = modkernel32.NewProc("GetACP")
)
func isEnglishOS(t *testing.T) bool {
const windows_1252 = 1252 // ANSI Latin 1; Western European (Windows)
r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
acp := uint32(r0)
return acp == windows_1252
}
func runCmd(args ...string) ([]byte, error) {
removeUTF8BOM := func(b []byte) []byte {
if len(b) >= 3 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF {
......@@ -226,6 +214,14 @@ func runCmd(args ...string) ([]byte, error) {
return removeUTF8BOM(out), nil
}
func netshSpeaksEnglish(t *testing.T) bool {
out, err := runCmd("netsh", "help")
if err != nil {
t.Fatal(err)
}
return bytes.Contains(out, []byte("The following commands are available:"))
}
func netshInterfaceIPShowInterface(ipver string, ifaces map[string]bool) error {
out, err := runCmd("netsh", "interface", ipver, "show", "interface", "level=verbose")
if err != nil {
......@@ -273,8 +269,8 @@ func TestInterfacesWithNetsh(t *testing.T) {
if isWindowsXP(t) {
t.Skip("Windows XP netsh command does not provide required functionality")
}
if !isEnglishOS(t) {
t.Skip("English version of OS required for this test")
if !netshSpeaksEnglish(t) {
t.Skip("English version of netsh required for this test")
}
toString := func(name string, isup bool) string {
......@@ -447,8 +443,8 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) {
if isWindowsXP(t) {
t.Skip("Windows XP netsh command does not provide required functionality")
}
if !isEnglishOS(t) {
t.Skip("English version of OS required for this test")
if !netshSpeaksEnglish(t) {
t.Skip("English version of netsh required for this test")
}
outIPV4, err := runCmd("netsh", "interface", "ipv4", "show", "address")
......@@ -507,12 +503,20 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) {
}
}
func getmacSpeaksEnglish(t *testing.T) bool {
out, err := runCmd("getmac", "/?")
if err != nil {
t.Fatal(err)
}
return bytes.Contains(out, []byte("network adapters on a system"))
}
func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
if isWindowsXP(t) {
t.Skip("Windows XP does not have powershell command")
}
if !isEnglishOS(t) {
t.Skip("English version of OS required for this test")
if !getmacSpeaksEnglish(t) {
t.Skip("English version of getmac required for this test")
}
ift, err := Interfaces()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment