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: add/use testInChild helper #173

Merged
merged 1 commit into from
Oct 22, 2024
Merged

Conversation

kolyshkin
Copy link
Collaborator

Houston, we have a problem:

	$ go test -exec sudo -run AmbientCapSet -count 3 -v
	=== RUN   TestAmbientCapSet
	--- PASS: TestAmbientCapSet (0.00s)
	=== RUN   TestAmbientCapSet
	    capability_test.go:113: The test needs `CAP_SETPCAP`.
	--- SKIP: TestAmbientCapSet (0.00s)
	=== RUN   TestAmbientCapSet
	    capability_test.go:113: The test needs `CAP_SETPCAP`.
	--- SKIP: TestAmbientCapSet (0.00s)
	PASS
	ok  	github.com/moby/sys/capability	0.024s

The solution is, tests that manipulate capabilities should be run in a separate process.

Add a helper to do just that, and modify TestAmbientCapSet to use it. In particular, the child needs to call os.Exit (which it does directly, in the end, and also indirectly, via log.Fatal).

@kolyshkin
Copy link
Collaborator Author

Until we add a second test which changes capability (currently we only have one), this can be tested by using e.g -count 2.

Before:

[kir@kir-tp1 capability]$ go test -v -count 2 -exec sudo  -run TestAmbientCapSet .
=== RUN   TestAmbientCapSet
--- PASS: TestAmbientCapSet (0.00s)
=== RUN   TestAmbientCapSet
    capability_test.go:113: The test needs `CAP_SETPCAP`.
--- SKIP: TestAmbientCapSet (0.00s)
PASS
ok  	github.com/moby/sys/capability	0.021s

After:

[kir@kir-tp1 capability]$ go test -v -count 2 -exec sudo  -run TestAmbientCapSet .
=== RUN   TestAmbientCapSet
    capability_test.go:147: output from child:
        === RUN   TestAmbientCapSet
--- PASS: TestAmbientCapSet (0.00s)
=== RUN   TestAmbientCapSet
    capability_test.go:147: output from child:
        === RUN   TestAmbientCapSet
--- PASS: TestAmbientCapSet (0.00s)
PASS
ok  	github.com/moby/sys/capability	0.024s

@kolyshkin
Copy link
Collaborator Author

@lifubang can you review this one?

Houston, we have a problem:

	$ go test -exec sudo -run AmbientCapSet -count 3 -v
	=== RUN   TestAmbientCapSet
	--- PASS: TestAmbientCapSet (0.00s)
	=== RUN   TestAmbientCapSet
	    capability_test.go:113: The test needs `CAP_SETPCAP`.
	--- SKIP: TestAmbientCapSet (0.00s)
	=== RUN   TestAmbientCapSet
	    capability_test.go:113: The test needs `CAP_SETPCAP`.
	--- SKIP: TestAmbientCapSet (0.00s)
	PASS
	ok  	github.com/moby/sys/capability	0.024s

The solution is, tests that manipulate capabilities should be run in a
separate process.

Add a helper to do just that, and modify TestAmbientCapSet to use it. In
particular, the child needs to call os.Exit (which it does directly, in
the end, and also indirectly, via log.Fatal).

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
Copy link
Collaborator Author

I have re-reviewed this myself and added some more comments.

Since it's just a test case, and this is needed for #171, let's merge it now and [not] regret it later.

@kolyshkin kolyshkin merged commit 6fcc541 into moby:main Oct 22, 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.

1 participant