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
tests/cmd/snapctl: unset SNAP_CONTEXT for the suite #7843
tests/cmd/snapctl: unset SNAP_CONTEXT for the suite #7843
Conversation
This variable can also be used to specify the cookie to use for snapctl, and sometimes other tests can leak this env var, so to be safe just unset it in the start of our test to ensure that we always use SNAP_COOKIE for this test Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
@@ -47,6 +47,8 @@ var _ = Suite(&snapctlSuite{}) | |||
|
|||
func (s *snapctlSuite) SetUpTest(c *C) { | |||
os.Setenv("SNAP_COOKIE", "snap-context-test") | |||
// don't use SNAP_CONTEXT, in case other tests accidentally leak this | |||
os.Unsetenv("SNAP_CONTEXT") |
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 looks fine, it shouldn't be a problem if we unset it in the test binary.
Still, I don't see it being set anywhere in the package. AFAIK, when running go test ./..., each package would get built and run separately, so even if a test in another package sets SNAP_CONTEXT, this should not leak into the test in another package. Is it possible that the tests were executed by Go installed from a snap?
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 agree, it's weird, it would be nice to know where did it come from.
That being said, the change looks ok.
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.
Is it possible that the tests were executed by Go installed from a snap?
Yes this is exactly what I did, for some reason it doesn't happen when I just use ./run-checks --unit
instead
Still, I don't see it being set anywhere in the package
FWIW it is still set by snap-confine here:
snapd/cmd/snap-confine/snap-confine.c
Lines 462 to 463 in 9b212f0
// for compatibility, if facing older snapd. | |
setenv("SNAP_CONTEXT", snap_context, 1); |
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.
+1
@@ -47,6 +47,8 @@ var _ = Suite(&snapctlSuite{}) | |||
|
|||
func (s *snapctlSuite) SetUpTest(c *C) { | |||
os.Setenv("SNAP_COOKIE", "snap-context-test") | |||
// don't use SNAP_CONTEXT, in case other tests accidentally leak this | |||
os.Unsetenv("SNAP_CONTEXT") |
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 agree, it's weird, it would be nice to know where did it come from.
That being said, the change looks ok.
So after looking into it some more, the issue with this test is that I was running
instead of
and the former is go 1.13 and the latter will sneakily find my go 1.10 install in Lines 19 to 22 in 4c562a1
Why this test fails on go 1.13 and passes on go 1.10 is a bit of a mystery to me however. |
Actually this is because my go 1.10 is not from a snap and go 1.13 is, if I use go 1.10 from a snap it still fails:
|
This test specifically would fail when go was run from a snap, because snap-confine for the go snap would set SNAP_COOKIE from here:
snapd/cmd/snap-confine/snap-confine.c
Lines 462 to 463 in 9b212f0
which would then cause snapctl to pick up the SNAP_CONTEXT variable and not see that the SNAP_COOKIE variable is unset and show a help message. So if we unset this environment variable when running this test suite, we are protected against this possibility.
For reference, the test would fail like this: