git » chasquid » commit bbe9f41

protoio: Test some I/O errors

author Alberto Bertogli
2018-06-03 22:59:44 UTC
committer Alberto Bertogli
2018-06-03 23:04:57 UTC
parent 26017548eff8e9cd131a8956e73868b2a7e936ee

protoio: Test some I/O errors

This patch adds some test cases for I/O errors, in particular when
reading, writing and listing from files that don't exist or that we
shouldn't have permissions to access.

internal/protoio/protoio_test.go +19 -0

diff --git a/internal/protoio/protoio_test.go b/internal/protoio/protoio_test.go
index f917ffb..dd25229 100644
--- a/internal/protoio/protoio_test.go
+++ b/internal/protoio/protoio_test.go
@@ -87,3 +87,22 @@ func TestStore(t *testing.T) {
 		t.Errorf("expected [f], got %v - %v", ids, err)
 	}
 }
+
+func TestFileErrors(t *testing.T) {
+	dir := testlib.MustTempDir(t)
+	defer testlib.RemoveIfOk(t, dir)
+	pb := &testpb.M{Content: "hola"}
+
+	if err := WriteMessage("/proc/doesnotexist", pb, 0600); err == nil {
+		t.Errorf("write to /proc/doesnotexist worked, expected error")
+	}
+
+	if err := ReadMessage("/doesnotexist", pb); err == nil {
+		t.Errorf("read from /doesnotexist worked, expected error")
+	}
+
+	s := &Store{dir: "/doesnotexist"}
+	if ids, err := s.ListIDs(); !(ids == nil && err != nil) {
+		t.Errorf("list /doesnotexist worked (%v, %v), expected error", ids, err)
+	}
+}