Skip to content

Conversation

@thaJeztah
Copy link
Member

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.

Makefile Outdated
Comment on lines 25 to 33
.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 ../
Copy link
Member Author

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 -d to create a temporary directory for the go-local.mod ?
  • note that bash "pseudo files" (<(echo "replace github.com/moby/sys/mountinfo => ../mountinfo" | cat mount/go.mod -)) don't work; go REQUIRES a file, and it must have a .mod extension (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.md to a separate target?

Input/suggestions welcome; my initial goal here is to have some way to test against the local source 😅

@thaJeztah
Copy link
Member Author

@kolyshkin ptal; happy to hear your thoughts on this

@kolyshkin
Copy link
Collaborator

Perhaps we can just add the replace line to go.mod, do the test and remove it. Add it with a comment to have a marker to aid in removal.

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

Can also be done entirely in Makefile, of course...

@thaJeztah
Copy link
Member Author

Perhaps we can just add the replace line to go.mod, do the test and remove it. Add it with a comment to have a marker to aid in removal.

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)


- name: tests
run: ssh default 'cd /vagrant && make test'
run: ssh default 'cd /vagrant && make test && make test-local'
Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Member Author

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 . ;\
Copy link
Collaborator

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 \.

Copy link
Member Author

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 \
Copy link
Collaborator

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.

Copy link
Member Author

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 ../
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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.

@thaJeztah thaJeztah force-pushed the test_tip_tip branch 3 times, most recently from dcd4a3f to 12e05c2 Compare April 7, 2021 16:48
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)\")
Copy link
Collaborator

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

Suggested change
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.

Copy link
Member Author

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 ?

Copy link
Collaborator

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.

Comment on lines +29 to +31
cd mount \
&& go mod download -modfile=go-local.mod \
&& go test -modfile=go-local.mod $(RUN_VIA_SUDO) -v .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Suggested change
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 .

Copy link
Member Author

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.

Copy link
Collaborator

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

  1. the only difference between go.mod and go-local.mod is the replace directive we add;
  2. go mod download is not needed at all -- there is nothing to download, the module is here already;
  3. 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.

@kolyshkin
Copy link
Collaborator

@thaJeztah PTAL


.PHONY: all
all: lint test cross
all: clean lint test test-local cross
Copy link
Collaborator

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.

@kolyshkin kolyshkin mentioned this pull request Oct 25, 2021
@kolyshkin
Copy link
Collaborator

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

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.

2 participants