本文整理汇总了Golang中github.com/snapcore/snapd/cmd/snap.MockSyscallExec函数的典型用法代码示例。如果您正苦于以下问题:Golang MockSyscallExec函数的具体用法?Golang MockSyscallExec怎么用?Golang MockSyscallExec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MockSyscallExec函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSnapRunAppWithCommandIntegration
func (s *SnapSuite) TestSnapRunAppWithCommandIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// and run it!
err = snaprun.SnapRunApp("snapname.app", "my-command", []string{"arg1", "arg2"})
c.Assert(err, check.IsNil)
c.Check(execArg0, check.Equals, filepath.Join(dirs.LibExecDir, "snap-confine"))
c.Check(execArgs, check.DeepEquals, []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
"snap.snapname.app",
filepath.Join(dirs.LibExecDir, "snap-exec"),
"--command=my-command", "snapname.app", "arg1", "arg2"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:34,代码来源:cmd_run_test.go
示例2: TestSnapRunHookMissingHookIntegration
func (s *SnapSuite) TestSnapRunHookMissingHookIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
// Only create revision 42
snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
// and mock the server
s.mockServer(c)
// redirect exec
called := false
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
called = true
return nil
})
defer restorer()
err := snaprun.SnapRunHook("snapname", "unset", "missing-hook")
c.Assert(err, check.IsNil)
c.Check(called, check.Equals, false)
}
开发者ID:clobrano,项目名称:snappy,代码行数:25,代码来源:cmd_run_test.go
示例3: TestSnapRunHookUnsetRevisionIntegration
func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// Specifically pass "unset" which would use the active version.
_, err = snaprun.Parser().ParseArgs([]string{"run", "--hook=configure", "-r=unset", "snapname"})
c.Assert(err, check.IsNil)
c.Check(execArg0, check.Equals, filepath.Join(dirs.LibExecDir, "snap-confine"))
c.Check(execArgs, check.DeepEquals, []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
"snap.snapname.hook.configure",
filepath.Join(dirs.LibExecDir, "snap-exec"),
"--hook=configure", "snapname"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:34,代码来源:cmd_run_test.go
示例4: TestSnapRunHookSpecificRevisionIntegration
func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
// Create both revisions 41 and 42
snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(41),
})
snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
// and mock the server
s.mockServer(c)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// Run a hook on revision 41
_, err := snaprun.Parser().ParseArgs([]string{"run", "--hook=apply-config", "-r=41", "snapname"})
c.Assert(err, check.IsNil)
c.Check(execArg0, check.Equals, "/usr/bin/ubuntu-core-launcher")
c.Check(execArgs, check.DeepEquals, []string{
"/usr/bin/ubuntu-core-launcher",
"snap.snapname.hook.apply-config",
"snap.snapname.hook.apply-config",
"/usr/lib/snapd/snap-exec",
"--hook=apply-config", "snapname"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=41")
}
开发者ID:clobrano,项目名称:snappy,代码行数:40,代码来源:cmd_run_test.go
示例5: TestSnapRunAppIntegration
func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
// and mock the server
s.mockServer(c)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// and run it!
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, "/usr/bin/ubuntu-core-launcher")
c.Check(execArgs, check.DeepEquals, []string{
"/usr/bin/ubuntu-core-launcher",
"snap.snapname.app",
"snap.snapname.app",
"/usr/lib/snapd/snap-exec",
"snapname.app",
"--arg1", "arg2"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42")
}
开发者ID:clobrano,项目名称:snappy,代码行数:38,代码来源:cmd_run_test.go
示例6: TestSnapRunSaneEnvironmentHandling
func (s *SnapSuite) TestSnapRunSaneEnvironmentHandling(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
// and mock the server
s.mockServer(c)
// redirect exec
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execEnv = envv
return nil
})
defer restorer()
// set a SNAP{,_*} variable in the environment
os.Setenv("SNAP_NAME", "something-else")
os.Setenv("SNAP_ARCH", "PDP-7")
defer os.Unsetenv("SNAP_NAME")
defer os.Unsetenv("SNAP_ARCH")
// but unreleated stuff is ok
os.Setenv("SNAP_THE_WORLD", "YES")
defer os.Unsetenv("SNAP_THE_WORLD")
// and ensure those SNAP_ vars get overriden
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(execEnv, testutil.Contains, "SNAP_REVISION=42")
c.Check(execEnv, check.Not(testutil.Contains), "SNAP_NAME=something-else")
c.Check(execEnv, check.Not(testutil.Contains), "SNAP_ARCH=PDP-7")
c.Check(execEnv, testutil.Contains, "SNAP_THE_WORLD=YES")
}
开发者ID:clobrano,项目名称:snappy,代码行数:38,代码来源:cmd_run_test.go
示例7: TestSnapRunHookMissingRevisionIntegration
func (s *SnapSuite) TestSnapRunHookMissingRevisionIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
// Only create revision 42
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
return nil
})
defer restorer()
// Attempt to run a hook on revision 41, which doesn't exist
_, err = snaprun.Parser().ParseArgs([]string{"run", "--hook=configure", "-r=41", "snapname"})
c.Assert(err, check.NotNil)
c.Check(err, check.ErrorMatches, "cannot find .*")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:23,代码来源:cmd_run_test.go
示例8: TestSnapRunHookMissingHookIntegration
func (s *SnapSuite) TestSnapRunHookMissingHookIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
// Only create revision 42
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
called := false
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
called = true
return nil
})
defer restorer()
err = snaprun.SnapRunHook("snapname", "unset", "missing-hook")
c.Assert(err, check.ErrorMatches, `cannot find hook "missing-hook" in "snapname"`)
c.Check(called, check.Equals, false)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:24,代码来源:cmd_run_test.go
示例9: TestSnapRunHookSpecificRevisionIntegration
func (s *SnapSuite) TestSnapRunHookSpecificRevisionIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
// Create both revisions 41 and 42
snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{
Revision: snap.R(41),
})
snaptest.MockSnap(c, string(mockYaml), string(mockContents), &snap.SideInfo{
Revision: snap.R(42),
})
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// Run a hook on revision 41
_, err := snaprun.Parser().ParseArgs([]string{"run", "--hook=configure", "-r=41", "snapname"})
c.Assert(err, check.IsNil)
c.Check(execArg0, check.Equals, filepath.Join(dirs.LibExecDir, "snap-confine"))
c.Check(execArgs, check.DeepEquals, []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
"snap.snapname.hook.configure",
filepath.Join(dirs.LibExecDir, "snap-exec"),
"--hook=configure", "snapname"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=41")
}
开发者ID:elopio,项目名称:snappy,代码行数:36,代码来源:cmd_run_test.go
注:本文中的github.com/snapcore/snapd/cmd/snap.MockSyscallExec函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论