Easiest way to simulate no free disk space situation?

后端 未结 13 741
执笔经年
执笔经年 2021-02-03 20:11

I need to test my web app in a scenario where there’s no disk space remaining, i.e. I cannot write any more files. But I don’t want to fill my hard drive with junk just to make

相关标签:
13条回答
  • 2021-02-03 20:57

    Can't you use a Mock, and substitute the part of your code which actually writes to disk, with a fake test replacement which will throw the exception(s) you expect to see?

    0 讨论(0)
  • 2021-02-03 20:59

    I'm not sure of how to do it on OSX but on Linux, I'd probably put a disk quota on my test user and then run the app.

    Or maybe create a null file (a small one), format it as an ext3 partition, mount it using the loopback device and run the PHP app inside it. This would be closer to a physical disk that's short of space.

    0 讨论(0)
  • 2021-02-03 21:04

    When I needed to do this I created a virtual machine with limited space allocated to the virtual disk.

    0 讨论(0)
  • 2021-02-03 21:08

    Have you tried mount with -f -r ? It's not really low disk space, but it should throw an error from the same level.

    0 讨论(0)
  • 2021-02-03 21:12

    Create a disk/filesystem image in a regular file (of limited size) and loop mount it.

    But if you'll be doing this often I'd create a virtual machine—you'll find opportunity to reuse it.

    0 讨论(0)
  • 2021-02-03 21:13

    Wherever you obtain the remaining disk space, just comment it out and run your app with a replacement values such as 0.1, 0, -1

    0 讨论(0)
提交回复
热议问题