[Libguestfs] [PATCH libnbd 2/2] golang/tests: Test expected Errno

Nir Soffer nirsof at gmail.com
Sat Oct 23 20:47:42 UTC 2021


Use type assertion[1] to convert err to the concrete LibnbdError so we
can verify the expected Errno. The assertion will panic if err is not a
LibnbdError.

[1] https://tour.golang.org/methods/15

Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
 golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go b/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go
index 27540ce..0f81e76 100644
--- a/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go
+++ b/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go
@@ -18,7 +18,7 @@
 
 package libnbd
 
-import "fmt"
+import "syscall"
 import "testing"
 
 func Test610Error(t *testing.T) {
@@ -34,8 +34,7 @@ func Test610Error(t *testing.T) {
 	err = h.Pread(buf, 0, nil)
 	if err == nil {
 		t.Fatalf("expected an error from operation")
+	} else if err.(*LibnbdError).Errno != syscall.ENOTCONN {
+		t.Fatalf("unexpected error: %s", err)
 	}
-	fmt.Printf("error = %s\n", err)
-	/* XXX We expect the errno to be ENOTCONN, but I couldn't work
-	   out how to test it. */
 }
-- 
2.31.1




More information about the Libguestfs mailing list