Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
many: fix test cases to work with different DistroLibExecDir #3222
0281474
710add9
c094911
11cfe4d
b92eae2
8f9dd95
2c626ed
88adec0
10612e6
ceb483f
2f3b287
9b771dd
97cde96
f0969ab
9e05477
94cc0e1
f78d791
a004317
69bc196
5cecbe2
8967f3a
cea541b
999789f
| @@ -98,7 +98,7 @@ func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
morphis
Contributor
|
||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -126,7 +126,7 @@ func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -135,7 +135,7 @@ func (s *SnapSuite) TestSnapRunClassicAppIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml)+"confinement: classic\n", string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -163,7 +163,7 @@ func (s *SnapSuite) TestSnapRunClassicAppIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), "--classic", | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -172,7 +172,7 @@ func (s *SnapSuite) TestSnapRunAppWithCommandIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -199,7 +199,7 @@ func (s *SnapSuite) TestSnapRunAppWithCommandIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--command=my-command", "snapname.app", "arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -225,7 +225,7 @@ func (s *SnapSuite) TestSnapRunHookIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -252,7 +252,7 @@ func (s *SnapSuite) TestSnapRunHookIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -261,7 +261,7 @@ func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -288,7 +288,7 @@ func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42") | ||
| } | ||
| @@ -297,7 +297,7 @@ func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| // Create both revisions 41 and 42 | ||
| snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| @@ -326,7 +326,7 @@ func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.hook.configure", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "--hook=configure", "snapname"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=41") | ||
| } | ||
| @@ -398,14 +398,14 @@ func (s *SnapSuite) TestSnapRunErorsForMissingApp(c *check.C) { | ||
| func (s *SnapSuite) TestSnapRunErorrForUnavailableApp(c *check.C) { | ||
| _, err := snaprun.Parser().ParseArgs([]string{"run", "not-there"}) | ||
| - c.Assert(err, check.ErrorMatches, "cannot find current revision for snap not-there: readlink /snap/not-there/current: no such file or directory") | ||
| + c.Assert(err, check.ErrorMatches, fmt.Sprintf("cannot find current revision for snap not-there: readlink %s/not-there/current: no such file or directory", dirs.SnapMountDir)) | ||
| } | ||
| func (s *SnapSuite) TestSnapRunSaneEnvironmentHandling(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R(42), | ||
| @@ -451,8 +451,8 @@ func (s *SnapSuite) TestSnapRunIsReexeced(c *check.C) { | ||
| readlink string | ||
| expected bool | ||
| }{ | ||
| - {filepath.Join(dirs.SnapMountDir, "/usr/lib/snapd/snapd"), true}, | ||
| - {"/usr/lib/snapd/snapd", false}, | ||
| + {filepath.Join(dirs.SnapMountDir, dirs.CoreLibExecDir, "snapd"), true}, | ||
| + {filepath.Join(dirs.DistroLibExecDir, "snapd"), false}, | ||
| } { | ||
| osReadlinkResult = t.readlink | ||
| c.Check(snaprun.IsReexeced(), check.Equals, t.expected) | ||
| @@ -463,7 +463,7 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| // mock installed snap | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(filepath.Join(dirs.SnapMountDir, "core", "current", dirs.CoreLibExecDir))() | ||
| si := snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{ | ||
| Revision: snap.R("x2"), | ||
| @@ -473,7 +473,7 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| // pretend to be running from core | ||
| restorer := snaprun.MockOsReadlink(func(string) (string, error) { | ||
| - return filepath.Join(dirs.SnapMountDir, "/core/111//usr/bin/snap"), nil | ||
| + return filepath.Join(dirs.SnapMountDir, "core/111/usr/bin/snap"), nil | ||
| }) | ||
| defer restorer() | ||
| @@ -493,11 +493,11 @@ func (s *SnapSuite) TestSnapRunAppIntegrationFromCore(c *check.C) { | ||
| rest, err := snaprun.Parser().ParseArgs([]string{"run", "snapname.app", "--arg1", "arg2"}) | ||
| c.Assert(err, check.IsNil) | ||
| c.Assert(rest, check.DeepEquals, []string{"snapname.app", "--arg1", "arg2"}) | ||
| - c.Check(execArg0, check.Equals, filepath.Join(dirs.SnapMountDir, "/core/current", dirs.DistroLibExecDir, "snap-confine")) | ||
| + c.Check(execArg0, check.Equals, filepath.Join(dirs.SnapMountDir, "/core/current", dirs.CoreLibExecDir, "snap-confine")) | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| - filepath.Join(dirs.SnapMountDir, "/core/current", dirs.DistroLibExecDir, "snap-confine"), | ||
| + filepath.Join(dirs.SnapMountDir, "/core/current", dirs.CoreLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app", "--arg1", "arg2"}) | ||
| c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2") | ||
| } | ||
| @@ -507,7 +507,7 @@ func (s *SnapSuite) TestSnapRunXauthorityMigration(c *check.C) { | ||
| // below /tmp which the Xauthority migration expects. | ||
| dirs.SetRootDir(c.MkDir()) | ||
| defer func() { dirs.SetRootDir("/") }() | ||
| - defer mockSnapConfine()() | ||
| + defer mockSnapConfine(dirs.DistroLibExecDir)() | ||
| u, err := user.Current() | ||
| c.Assert(err, check.IsNil) | ||
| @@ -553,7 +553,7 @@ func (s *SnapSuite) TestSnapRunXauthorityMigration(c *check.C) { | ||
| c.Check(execArgs, check.DeepEquals, []string{ | ||
| filepath.Join(dirs.DistroLibExecDir, "snap-confine"), | ||
| "snap.snapname.app", | ||
| - filepath.Join(dirs.DistroLibExecDir, "snap-exec"), | ||
| + filepath.Join(dirs.CoreLibExecDir, "snap-exec"), | ||
| "snapname.app"}) | ||
| expectedXauthPath := filepath.Join(dirs.XdgRuntimeDirBase, u.Uid, ".Xauthority") | ||
| @@ -20,8 +20,12 @@ | ||
| package builtin_test | ||
| import ( | ||
| + "fmt" | ||
| + "path/filepath" | ||
| + | ||
| . "gopkg.in/check.v1" | ||
| + "github.com/snapcore/snapd/dirs" | ||
| "github.com/snapcore/snapd/interfaces" | ||
| "github.com/snapcore/snapd/interfaces/apparmor" | ||
| "github.com/snapcore/snapd/interfaces/builtin" | ||
| @@ -196,11 +200,11 @@ apps: | ||
| func (s *ContentSuite) TestResolveSpecialVariable(c *C) { | ||
| info := snaptest.MockInfo(c, "name: name", &snap.SideInfo{Revision: snap.R(42)}) | ||
| - c.Check(builtin.ResolveSpecialVariable("foo", info), Equals, "/snap/name/42/foo") | ||
zyga
Contributor
|
||
| - c.Check(builtin.ResolveSpecialVariable("$SNAP/foo", info), Equals, "/snap/name/42/foo") | ||
| + c.Check(builtin.ResolveSpecialVariable("foo", info), Equals, filepath.Join(dirs.CoreSnapMountDir, "name/42/foo")) | ||
| + c.Check(builtin.ResolveSpecialVariable("$SNAP/foo", info), Equals, filepath.Join(dirs.CoreSnapMountDir, "name/42/foo")) | ||
| c.Check(builtin.ResolveSpecialVariable("$SNAP_DATA/foo", info), Equals, "/var/snap/name/42/foo") | ||
| c.Check(builtin.ResolveSpecialVariable("$SNAP_COMMON/foo", info), Equals, "/var/snap/name/common/foo") | ||
| - c.Check(builtin.ResolveSpecialVariable("$SNAP", info), Equals, "/snap/name/42") | ||
| + c.Check(builtin.ResolveSpecialVariable("$SNAP", info), Equals, filepath.Join(dirs.CoreSnapMountDir, "name/42")) | ||
| c.Check(builtin.ResolveSpecialVariable("$SNAP_DATA", info), Equals, "/var/snap/name/42") | ||
| c.Check(builtin.ResolveSpecialVariable("$SNAP_COMMON", info), Equals, "/var/snap/name/common") | ||
| } | ||
| @@ -226,8 +230,8 @@ slots: | ||
| spec := &mount.Specification{} | ||
| c.Assert(spec.AddConnectedPlug(s.iface, plug, nil, slot, nil), IsNil) | ||
| expectedMnt := []mount.Entry{{ | ||
| - Name: "/snap/producer/5/export", | ||
| - Dir: "/snap/consumer/7/import", | ||
| + Name: filepath.Join(dirs.CoreSnapMountDir, "producer/5/export"), | ||
| + Dir: filepath.Join(dirs.CoreSnapMountDir, "consumer/7/import"), | ||
| Options: []string{"bind", "ro"}, | ||
| }} | ||
| c.Assert(spec.MountEntries(), DeepEquals, expectedMnt) | ||
| @@ -257,8 +261,8 @@ slots: | ||
| spec := &mount.Specification{} | ||
| c.Assert(spec.AddConnectedPlug(s.iface, plug, nil, slot, nil), IsNil) | ||
| expectedMnt := []mount.Entry{{ | ||
| - Name: "/snap/producer/5/export", | ||
| - Dir: "/snap/consumer/7/import", | ||
| + Name: filepath.Join(dirs.CoreSnapMountDir, "producer/5/export"), | ||
| + Dir: filepath.Join(dirs.CoreSnapMountDir, "consumer/7/import"), | ||
| Options: []string{"bind", "ro"}, | ||
| }} | ||
| c.Assert(spec.MountEntries(), DeepEquals, expectedMnt) | ||
| @@ -267,12 +271,12 @@ slots: | ||
| err := apparmorSpec.AddConnectedPlug(s.iface, plug, nil, slot, nil) | ||
| c.Assert(err, IsNil) | ||
| c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) | ||
| - expected := ` | ||
| + expected := fmt.Sprintf(` | ||
| # In addition to the bind mount, add any AppArmor rules so that | ||
| # snaps may directly access the slot implementation's files | ||
| # read-only. | ||
| -/snap/producer/5/export/** mrkix, | ||
| -` | ||
| +%s/producer/5/export/** mrkix, | ||
| +`, dirs.CoreSnapMountDir) | ||
| c.Assert(apparmorSpec.SnippetForTag("snap.consumer.app"), Equals, expected) | ||
| } | ||
Pardon my ignorance, but it looks like the argument for
mockSnapConfine()is always dirs.DistroLibExecDir - do we really need this new argument in this case?