Skip to content

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 <kolyshkin@gmail.com>
@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.

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