-
Notifications
You must be signed in to change notification settings - Fork 47
mount: also test against local mountinfo source code #68
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
Conversation
Makefile
Outdated
| .PHONY: test-local | ||
| test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") | ||
| test-local: clean | ||
| echo "replace github.com/moby/sys/mountinfo => ../mountinfo" | cat mount/go.mod - > mount/go-local.mod \ | ||
| && cd mount \ | ||
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . ;\ | ||
| rm go-local.* | ||
| cd ../ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit that I've been going back-and-forth what the cleanest way is to implement this;
- use
mktemp -dto create a temporary directory for thego-local.mod? - note that bash "pseudo files" (
<(echo "replace github.com/moby/sys/mountinfo => ../mountinfo" | cat mount/go.mod -)) don't work;goREQUIRES a file, and it must have a.modextension (possibly something we should request to be changed, so that, e.g.STDIN/-could be supported? - combine this with the
test:target? (less flexible, but perhaps cleaner?) - split creation of
mount/go-local.mdto a separate target?
Input/suggestions welcome; my initial goal here is to have some way to test against the local source 😅
|
@kolyshkin ptal; happy to hear your thoughts on this |
|
Perhaps we can just add the Something like this (as a script in mount directory, UNTESTED): #!/bin/bash
MARKER='# Added temporarily by test-latest'
trap "sed -i \"/^${MARKER}/,$d\" go.mod" EXIT
if ! grep -q "^${MARKER}$" go.mod; then
cat << EOF >> go.mod
$MARKER
replace replace github.com/moby/sys/mountinfo => ../mountinfo
EOF
fi
go test -v .And in the top makefile: .PHONY: test-latest
test-latest:
./mount/test-latestCan also be done entirely in Makefile, of course... |
I considered something like that, but (personally) prefer not to modify files that are in version control; that way we also don't have to revert the change (and allow running it locally as well, without accidentally modifying the file) |
.github/workflows/test.yml
Outdated
|
|
||
| - name: tests | ||
| run: ssh default 'cd /vagrant && make test' | ||
| run: ssh default 'cd /vagrant && make test && make test-local' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be just make test test-local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...but rather than having a need to call test-local separately, I'd add test: test-local dependency into the Makefile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense; tests run really fast, so shouldn't be an issue to always run both
Makefile
Outdated
| echo 'replace github.com/moby/sys/mountinfo => ../mountinfo' | cat mount/go.mod - > mount/go-local.mod \ | ||
| && cd mount \ | ||
| && go mod download -modfile=go-local.mod \ | ||
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . ;\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a space before \.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your other comments about continuation; I'll remove this, and make the rm just rm -f mount/go-local.*
Makefile
Outdated
| .PHONY: test-local | ||
| test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") | ||
| test-local: clean | ||
| echo 'replace github.com/moby/sys/mountinfo => ../mountinfo' | cat mount/go.mod - > mount/go-local.mod \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here continuation (\ and && on the next line) is not needed. Make executes the commands via shell one by one, if a command fails, it stops.
The continuation is needed after cd as it won't affect the next command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Good one; I sometimes get confused when to \ and when not in Makefiles
Makefile
Outdated
| && go mod download -modfile=go-local.mod \ | ||
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . ;\ | ||
| rm go-local.* | ||
| cd ../ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed (every command is run via its own shell).
Makefile
Outdated
| .PHONY: test | ||
| test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") | ||
| test: | ||
| test: clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed? Even if mount/go-local.mod is present, it does not affect go test in any way (AFAIK).
Makefile
Outdated
| # changes in mountinfo. | ||
| .PHONY: test-local | ||
| test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") | ||
| test-local: clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean dependency is not needed, as we're overwriting the file anyway.
dcd4a3f to
12e05c2
Compare
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 <[email protected]>
| $(RM) mount/go-local.* | ||
|
|
||
| .PHONY: test | ||
| test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change this to
| test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") | |
| test test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") |
(and move up) to avoid repetition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and move up) to avoid repetition.
You mean, move test-local above test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, combine the two lines
test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\")
....
test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\")into one
test test-local: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\")and move it up next to SUDO definition.
| cd mount \ | ||
| && go mod download -modfile=go-local.mod \ | ||
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cd mount \ | |
| && go mod download -modfile=go-local.mod \ | |
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . | |
| cp mount/go.sum mount/go-local.sum | |
| cd mount && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . |
or
| cd mount \ | |
| && go mod download -modfile=go-local.mod \ | |
| && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . | |
| ln -sf go.sum mount/go-local.sum | |
| cd mount && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if understand this change; go-local.sum will be different than go.sum, because it's using different versions of the dependency; the go mod download -modfile=go-local.mod may pull other versions of dependencies, because mountinfo ("main branch") may be using different versions of dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a while to figure out why I originally suggested that :)
This is because
- the only difference between
go.modandgo-local.modis the replace directive we add; go mod downloadis not needed at all -- there is nothing to download, the module is here already;- for the modules with relevant paths (aka local modules), no checksums are ever needed or recorded.
This means that existing go.sum file is totally adequate, so copying or linking it is sufficient. You can even try to do go mod tidy -modfile go-local.mod and see what happens -- in fact it will remove the checksums for mountinfo v0.4.1 package (as it is no longer used), but having this extra lines is not a problem for tests.
|
@thaJeztah PTAL |
|
|
||
| .PHONY: all | ||
| all: lint test cross | ||
| all: clean lint test test-local cross |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: no need to have test-local here as test depends on it.
|
I have carried this to #87, with the following changes (explained above): diff --git a/Makefile b/Makefile
index d7683d9..b4a196e 100644
--- a/Makefile
+++ b/Makefile
@@ -4,31 +4,29 @@ 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: clean lint test test-local 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-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 go.mod. This allows catching regressions / breaking
+# 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: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\")
test-local:
echo 'replace github.com/moby/sys/mountinfo => ../mountinfo' | cat mount/go.mod - > mount/go-local.mod
- cd mount \
- && go mod download -modfile=go-local.mod \
- && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v .
+ cp mount/go.sum mount/go-local.sum
+ cd mount && go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v .
$(RM) mount/go-local.*
.PHONY: lint |
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.