From bb17c6a2b5011993a27afafe45870a4f80697829 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 25 Oct 2021 11:04:03 -0700 Subject: [PATCH 1/2] mountinfo: TestMountedBy: require root This test needs root as its setup performs some mounts. It used to require root (indirectly via requireOpenat2), but after commit 098ed008148 this is no longer the case, and thus if passwordless sudo is not available, the test fails: [kir@kir-rhat sys]$ make test sudo: a password is required for p in mountinfo mount signal symlink; do \ (cd $p && go test -v .); \ done === RUN TestMountedBy mounted_linux_test.go:221: setup failed: mount /tmp/TestMountedBy1220310657/tmpfs-mount: operation not permitted --- FAIL: TestMountedBy (0.00s) Add an explicit root check to fix this. Fixes: 098ed008148 Signed-off-by: Kir Kolyshkin --- mountinfo/mounted_linux_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mountinfo/mounted_linux_test.go b/mountinfo/mounted_linux_test.go index 231dd741..f807dbf3 100644 --- a/mountinfo/mounted_linux_test.go +++ b/mountinfo/mounted_linux_test.go @@ -215,6 +215,10 @@ func tryOpenat2() error { } func TestMountedBy(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("root required") + } + dir, mounts, err := prepareMounts(t) defer cleanupMounts(t, dir, mounts) if err != nil { From 77f548c41960159d485ea0c55506379405526c62 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 9 Mar 2021 11:37:35 +0100 Subject: [PATCH 2/2] mount: also test against local mountinfo source code mount depends on mountinfo, but defaults to the release specified in go.mod. This change adds a new test to also run against the local code so that we can catch regressions / breaking changes. Signed-off-by: Sebastiaan van Stijn Signed-off-by: Kir Kolyshkin --- .gitignore | 1 + Makefile | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5ec4c027 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/mount/go-local.* diff --git a/Makefile b/Makefile index 59d302fc..0548139e 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,32 @@ BINDIR ?= _build/bin CROSS ?= linux/arm linux/arm64 linux/ppc64le linux/s390x \ freebsd/amd64 openbsd/amd64 darwin/amd64 darwin/arm64 windows/amd64 SUDO ?= sudo -n +test test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") .PHONY: all -all: lint test cross +all: clean lint test cross + +.PHONY: clean +clean: + $(RM) mount/go-local.* .PHONY: test -test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") -test: +test: test-local for p in $(PACKAGES); do \ (cd $$p && go test $(RUN_VIA_SUDO) -v .); \ done +# Test the mount module against the local mountinfo source code instead of the +# release specified in its go.mod. This allows catching regressions / breaking +# changes in mountinfo. +.PHONY: test-local +test-local: MOD = -modfile=go-local.mod +test-local: + echo 'replace github.com/moby/sys/mountinfo => ../mountinfo' | cat mount/go.mod - > mount/go-local.mod + # Run go mod tidy to make sure mountinfo dependency versions are met. + cd mount && go mod tidy $(MOD) && go test $(MOD) $(RUN_VIA_SUDO) -v . + $(RM) mount/go-local.* + .PHONY: lint lint: $(BINDIR)/golangci-lint $(BINDIR)/golangci-lint version