1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

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.
This commit is contained in:
Alberto Bertogli
2018-06-03 23:59:44 +01:00
parent 26017548ef
commit bbe9f4187d

View File

@@ -87,3 +87,22 @@ func TestStore(t *testing.T) {
t.Errorf("expected [f], got %v - %v", ids, err) 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)
}
}