]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Stop accessing SetupDiGetDeviceInfoListDetail() output on error
authorSimon Rozman <simon@rozman.si>
Mon, 4 Feb 2019 10:45:37 +0000 (11:45 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 5 Feb 2019 11:59:42 +0000 (12:59 +0100)
The data returned by SetupDiGetDeviceInfoListDetail() is nil on error
which will cause the test to crash should the function fail.

Signed-off-by: Simon Rozman <simon@rozman.si>
setupapi/setupapi_windows_test.go

index 062b6bd3e9874e3c9269b111b76369edc77a6c80..17d6d8e36ff04b427d3c64f741ef881b29d6f57b 100644 (file)
@@ -99,18 +99,18 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
        data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
        if err != nil {
                t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
-       }
-
-       if data.ClassGUID != deviceClassNetGUID {
-               t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
-       }
+       } else {
+               if data.ClassGUID != deviceClassNetGUID {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
+               }
 
-       if data.RemoteMachineHandle != windows.Handle(0) {
-               t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
-       }
+               if data.RemoteMachineHandle != windows.Handle(0) {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
+               }
 
-       if data.RemoteMachineName != "" {
-               t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
+               if data.RemoteMachineName != "" {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
+               }
        }
 }
 
@@ -124,18 +124,18 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
        data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
        if err != nil {
                t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
-       }
-
-       if data.ClassGUID != deviceClassNetGUID {
-               t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
-       }
+       } else {
+               if data.ClassGUID != deviceClassNetGUID {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned different class GUID")
+               }
 
-       if data.RemoteMachineHandle == windows.Handle(0) {
-               t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
-       }
+               if data.RemoteMachineHandle == windows.Handle(0) {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
+               }
 
-       if data.RemoteMachineName != computerName {
-               t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
+               if data.RemoteMachineName != computerName {
+                       t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
+               }
        }
 }