Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/Chown #4213

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

os/Chown #4213

wants to merge 4 commits into from

Conversation

leongross
Copy link

Add os.Chown()

Signed-off-by: leongross <leon.gross@9elements.com>
src/os/os_chmod_test.go Outdated Show resolved Hide resolved
src/os/os_chmod_test.go Outdated Show resolved Hide resolved
src/os/os_chmod_test.go Outdated Show resolved Hide resolved
src/os/os_chmod_test.go Show resolved Hide resolved
@leongross
Copy link
Author

leongross commented Apr 3, 2024

To design meaningful test cases for chown, I think you would need multiple users with different uids and gids and a user who has permission to change ownership of a file to this, a super user. In my opinion, there are 2 ways to integrate this:

  1. update the container image for the CI so that there are accounts with said properties
  2. mocking the file system and permissions

The problem I see with solution 2 is that the implementation of chown relies on the syscall chown, so I wouldn't know how to mock that.

I would appreciate your input on that @rminnich

EDIT: Maybe I am mistaken but as I see it, golang does not do any of the described tests but checks for an error of an invalid gid, maybe this is the way to go here as well?

Signed-off-by: leongross <leon.gross@9elements.com>
@leongross
Copy link
Author

@deadprogram do you have an opinion on that?

@leongross
Copy link
Author

@deadprogram

@leongross
Copy link
Author

@rminnich

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to keep this lightly tested, for example by checking that the syscall returns an expected permission error (or even just "file not found" - it also means the call works at least somewhat).

Yes it would be great to be able to test everything, but that's very hard to do for things like this and you'll end up putting a lot of effort into what's essentially just a wrapper for a libc function.

src/os/file_anyos.go Outdated Show resolved Hide resolved
Signed-off-by: leongross <leon.gross@9elements.com>
@leongross leongross force-pushed the os/chown branch 4 times, most recently from cbcb173 to 71d571e Compare May 3, 2024 09:55
Signed-off-by: leongross <leon.gross@9elements.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants