How to test a function that deals with setting file ownership without being root
I wrote a function that copies the /etc/skel directory on a linux machine during a "create new user" RPC call. Now, there is quite a few things about this I want to test, for example the files in /etc/skel and the targets of symlinks should not 开发者_开发知识库have changed permissions afterwards, whereas the copied files including the actual symlinks should have a changed owner. Now, i can create my test directory and files using mkdtemp and stuff, but I can't chown those to another user without root privileges. How would you write a test for this?
You could make an object which does the chmod, and inject a mock when testing. This mock would not really do the chmod, but make it possible to test if it was called with the right parameters.
精彩评论