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 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 {