diff options
author | Simon Rozman <simon@rozman.si> | 2019-08-02 14:53:02 +0200 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2019-08-02 15:18:58 +0200 |
commit | 73698066d142a82468aa1c4c2bef52bbef919a7c (patch) | |
tree | a8940a7fdf3b2022d938b656a5bfd7c29700e3c3 /tun/wintun/setupapi | |
parent | 05ece4d167cf26c95ef58cc80e912dbd43d44c86 (diff) |
wintun: refactor `err == nil` error checking
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun/setupapi')
-rw-r--r-- | tun/wintun/setupapi/setupapi_windows_test.go | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/tun/wintun/setupapi/setupapi_windows_test.go b/tun/wintun/setupapi/setupapi_windows_test.go index 48a0f05..a9e6b89 100644 --- a/tun/wintun/setupapi/setupapi_windows_test.go +++ b/tun/wintun/setupapi/setupapi_windows_test.go @@ -22,24 +22,24 @@ func init() { func TestSetupDiCreateDeviceInfoListEx(t *testing.T) { devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "") - if err == nil { - devInfoList.Close() - } else { + if err != nil { t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error()) + } else { + devInfoList.Close() } devInfoList, err = SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName) - if err == nil { - devInfoList.Close() - } else { + if err != nil { t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error()) + } else { + devInfoList.Close() } devInfoList, err = SetupDiCreateDeviceInfoListEx(nil, 0, "") - if err == nil { - devInfoList.Close() - } else { + if err != nil { t.Errorf("Error calling SetupDiCreateDeviceInfoListEx(nil): %s", err.Error()) + } else { + devInfoList.Close() } } @@ -257,20 +257,20 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) { func TestSetupDiGetClassDevsEx(t *testing.T) { devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName) - if err == nil { - devInfoList.Close() - } else { + if err != nil { t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error()) + } else { + devInfoList.Close() } devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "") - if err == nil { - devInfoList.Close() - t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail") - } else { + if err != nil { if errWin, ok := err.(windows.Errno); !ok || errWin != windows.ERROR_INVALID_PARAMETER { t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail with ERROR_INVALID_PARAMETER") } + } else { + devInfoList.Close() + t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail") } } @@ -400,12 +400,12 @@ func TestSetupDiClassNameFromGuidEx(t *testing.T) { } _, err = SetupDiClassNameFromGuidEx(nil, "") - if err == nil { - t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail") - } else { + if err != nil { if errWin, ok := err.(windows.Errno); !ok || errWin != windows.ERROR_INVALID_USER_BUFFER { t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail with ERROR_INVALID_USER_BUFFER") } + } else { + t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail") } } @@ -464,12 +464,12 @@ func TestSetupDiGetSelectedDevice(t *testing.T) { } err = devInfoList.SetSelectedDevice(nil) - if err == nil { - t.Errorf("SetupDiSetSelectedDevice(nil) should fail") - } else { + if err != nil { if errWin, ok := err.(windows.Errno); !ok || errWin != windows.ERROR_INVALID_PARAMETER { t.Errorf("SetupDiSetSelectedDevice(nil) should fail with ERROR_INVALID_USER_BUFFER") } + } else { + t.Errorf("SetupDiSetSelectedDevice(nil) should fail") } } |