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

capability: use strings.CutPrefix; test improvements #162

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

kolyshkin
Copy link
Collaborator

See individual commits for details. Originally part of #159.

First, make capability_test.go a separate package so we are limited to
testing the external API (as opposed to e.g. state_linux_test.go in
which we test internal stuff as well).

Second, streamline the linux/non-linux code so it's easier to read and
copy/paste (in general, we only want to check that non-linux functions
can be called and return an error).

Third, change some non-fatal errors to use t.Errorf.

Fourth, use want/got everywhere in error messages, and add more context
to some errors.

Nothing here is critical or makes any noticeable impact on tests.

Signed-off-by: Kir Kolyshkin <[email protected]>
This makes it slightly less cryptic (in particular, replacing a literal
tab with "\t"), and also silences this codespell warning:

> ./capability/capability_linux.go:311: nd ==> and, 2nd

While at it, add a simple test for the method.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin kolyshkin mentioned this pull request Sep 27, 2024
@kolyshkin kolyshkin marked this pull request as ready for review September 27, 2024 01:37
default:
if err == nil {
t.Fatal(runtime.GOOS, ": want error, got nil")
}
return
case "linux":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it that you can have default as the first case in switch; it improves readability in here (otherwise I would have to add a comment saying "Below is linux-only stuff").

@kolyshkin
Copy link
Collaborator Author

@thaJeztah @tianon PTAL 🙏

I have some more changes that depend on these.

@tianon tianon merged commit aa7aee5 into moby:main Oct 9, 2024
19 checks passed
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.

2 participants