8000 CI: run tests that need root as root by Luap99 · Pull Request #2878 · containers/image · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CI: run tests that need root as root #2878

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

Merged
merged 3 commits into from
Jun 27, 2025
Merged

Conversation

Luap99
Copy link
Member
@Luap99 Luap99 commented Jun 24, 2025

This is a quick and dirty fix but should get the job done and ensures the tests are actually run by CI. The idea is simple to not waste resources we just look for the test names using
ensureTestCanCreateImages() to skip as rootless.

@Luap99
Copy link
Member Author
Luap99 commented Jun 24, 2025
--- PASS: TestWriteRead (0.04s)
=== RUN   TestDuplicateName
--- PASS: TestDuplicateName (0.03s)
=== RUN   TestDuplicateID
--- PASS: TestDuplicateID (0.04s)
=== RUN   TestDuplicateNameID
--- PASS: TestDuplicateNameID (0.04s)
=== RUN   TestSize
--- PASS: TestSize (0.04s)
=== RUN   TestDuplicateBlob
--- PASS: TestDuplicateBlob (0.09s)

seems to work

@Luap99 Luap99 marked this pull request as ready for review June 24, 2025 19:18
Copy link
Collaborator
@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

# that matches all these names.
# With that we don't have to run everything twice and can just run the ones that
# actually need to be root.
test_filter=$(sed -n '$!N;/\n[[:space:]]ensureTestCanCreateImages(.*$/P;D' storage/*_test.go |
Copy link
Collaborator

Choose a reason for hiding this comment

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

The sed command looks correct but I worry it will be hard to maintain.

git grep --show-function does something similar natively (looking for a preceding line that doesn’t start with whitespace), maybe
git grep -h --show-function ensureTestCanCreateImages | sed -n 's/func \(Test[[:alnum:]]*\)(.*/^\1\$/p'

That would also avoid the need for precise positioning of ensureTestCanCreateImages.

Copy link
Member Author

Choose a reason for hiding this comment

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

git grep --show-function

huh, didn't know that is a thing. That certainly looks much nicer.

test_filter=$(sed -n '$!N;/\n[[:space:]]ensureTestCanCreateImages(.*$/P;D' storage/*_test.go |
sed 's/func \([a-zA-Z0-9_]*\).*/^\1\$/' |
paste -sd "|" -)
go test -v -run "$test_filter" ./storage/
Copy link
Collaborator
@mtrmac mtrmac Jun 25, 2025

Choose a reason for hiding this comment

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

This does not handle BUILDTAGS, we run the test twice with different flags tags (admittedly that difference doesn’t matter for these tests) —and I’ll need to add more BUILDFLAGS in an unrelated PR.

Doing this via a Make rule would keep all of that logic centralized.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah I didn't pay to much attention for this as the storage dir didn't need it.

I can move the entire logic it to the Makefile if you like, but then what should I call the target test-root-only?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, naming that is hard, and it seems unlikely to have external users. (And if we did add test-root-only, should we overengineer the logic to not be just ensureTestCanCreateImages, which is not exactly “root only”? Let’s just not deal with that, I think.)

Maybe make test BUILDTAGS="$BUILDTAGS" BUILDFLAGS=$the_new_filter here, and use BUILDFLAGS += in the Makefile. That would be sufficient to centralize the Go option logic, without committing to the root/non-root test split.

Copy link
Collaborator

Choose a reason for hiding this comment

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

flag provided but not defined: -run

I’m afraid that using BUILDFLAGS for this doesn’t work — we’d need something like specialized TESTFLAGS. (Also, #2873 (comment) , for -v)

@Luap99 Luap99 force-pushed the test-root branch 4 times, most recently from 869cfc7 to 58e39c6 Compare June 26, 2025 11:45
Luap99 added 3 commits June 26, 2025 15:57
For CI it would be useful if we can pass extra arguments to go test such
as -v or extra filters via -run.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This is a quick and dirty fix but should get the job done and ensures
the tests are actually run by CI. The idea is simple to not waste
resources we just look for the test names using
ensureTestCanCreateImages() to skip as rootless.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
For CI logs it is extremely useful to get the full output to see what
tests were run and skipped so one can verifiy CI is working as expected
and runs all out tests.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
@Luap99
Copy link
Member Author
Luap99 commented Jun 26, 2025

Ok now it should work. Makefile and git gave me lot of troubles. Makefile var really want to interpret the $ in the run filter even inside single quotes so I had to double escape it with $$

Copy link
Collaborator
@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

@mtrmac mtrmac merged commit fee667a into containers:main Jun 27, 2025
10 checks passed
@mtrmac
Copy link
Collaborator
mtrmac commented Jun 27, 2025

Makefile var really want to interpret the $ in the run filter even inside single quotes so I had to double escape it with $$

For reference, https://www.gnu.org/software/make/manual/make.html#Overriding : I didn’t know that make var=$abc causes $a to be expanded later, nor that make var:=$abc is possible.

@Luap99 Luap99 deleted the test-root branch June 27, 2025 12:08
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
0