From 0e83c95fac827ca739fd115f7560868c411f5de8 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 22 Mar 2022 17:08:15 +1100 Subject: [PATCH] virtcontainers: Run mock hook from build tree rather than system bin dir Running unit tests should generally have minimal dependencies on things outside the build tree. It *definitely* shouldn't modify system wide things outside the build tree. Currently the runtime "make test" target does so, though. Several of the tests in src/runtime/pkg/katautils/hook_test.go require a sample hook binary. They expect this hook in /usr/bin/virtcontainers/bin/test/hook, so the makefile, as root, installs the test binary to that location. Go tests automatically run within the package's directory though, so there's no need to use a system wide path. We can use a relative path to the binary build within the tree just as easily. fixes #3941 Signed-off-by: David Gibson --- src/runtime/Makefile | 6 ++---- src/runtime/pkg/katautils/hook_test.go | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/runtime/Makefile b/src/runtime/Makefile index 9f34c3da76..f87e72e583 100644 --- a/src/runtime/Makefile +++ b/src/runtime/Makefile @@ -589,12 +589,10 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit generate-config: $(CONFIGS) -test: install-hook go-test +test: hook go-test -install-hook: +hook: make -C virtcontainers hook - echo "installing mock hook" - sudo -E make -C virtcontainers install go-test: $(GENERATED_FILES) go clean -testcache diff --git a/src/runtime/pkg/katautils/hook_test.go b/src/runtime/pkg/katautils/hook_test.go index 6109b55499..50452974b6 100644 --- a/src/runtime/pkg/katautils/hook_test.go +++ b/src/runtime/pkg/katautils/hook_test.go @@ -20,7 +20,7 @@ import ( var testKeyHook = "test-key" var testContainerIDHook = "test-container-id" var testControllerIDHook = "test-controller-id" -var testBinHookPath = "/usr/bin/virtcontainers/bin/test/hook" +var testBinHookPath = "../../virtcontainers/hook/mock/hook" var testBundlePath = "/test/bundle" func getMockHookBinPath() string {