Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force an IOException in jimfs

I have file related code to test where I would like to test my error handling for an existing file that I cannot read.

class SomeClass {
    //...
    public void load(Path path) {
       if (!Files.isRegularFile(path)) {
           return null;
       }
       //...
       try {
           // ...
       catch (IOException e) {
           // cleanup
       }
    }
}

I am using jimfs to isolate the tests from the real file system.

So how would I create a file on jimfs that is not readable?

I have already tried assigning posix permissions and a different user to the path through Files.setAttribute on the desired path, both of which seem to have been ignored when attempting to read or write to the path.

like image 633
EdJoJob Avatar asked Oct 31 '22 06:10

EdJoJob


1 Answers

Unfortunately there isn't currently any support for actual permission/access checking for files in Jimfs. It's something that I think would be good to have, but I haven't worked out the details: see this issue and this somewhat related issue.

like image 189
ColinD Avatar answered Dec 31 '22 01:12

ColinD