本文整理汇总了Golang中github.com/snapcore/snapd/testutil.MockCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang MockCommand函数的具体用法?Golang MockCommand怎么用?Golang MockCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MockCommand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *FirstBootTestSuite) SetUpTest(c *C) {
tempdir := c.MkDir()
dirs.SetRootDir(tempdir)
// mock the world!
err := os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "snaps"), 0755)
c.Assert(err, IsNil)
err = os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "assertions"), 0755)
c.Assert(err, IsNil)
err = os.MkdirAll(dirs.SnapServicesDir, 0755)
c.Assert(err, IsNil)
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
s.systemctl = testutil.MockCommand(c, "systemctl", "")
s.mockUdevAdm = testutil.MockCommand(c, "udevadm", "")
err = ioutil.WriteFile(filepath.Join(dirs.SnapSeedDir, "seed.yaml"), nil, 0644)
c.Assert(err, IsNil)
rootPrivKey, _ := assertstest.GenerateKey(1024)
storePrivKey, _ := assertstest.GenerateKey(752)
s.storeSigning = assertstest.NewStoreStack("can0nical", rootPrivKey, storePrivKey)
s.restore = sysdb.InjectTrusted(s.storeSigning.Trusted)
s.brandPrivKey, _ = assertstest.GenerateKey(752)
s.brandSigning = assertstest.NewSigningDB("my-brand", s.brandPrivKey)
ovld, err := overlord.New()
c.Assert(err, IsNil)
s.overlord = ovld
}
开发者ID:pedronis,项目名称:snappy,代码行数:31,代码来源:firstboot_test.go
示例2: SetUpTest
func (ms *mgrsSuite) SetUpTest(c *C) {
ms.tempdir = c.MkDir()
dirs.SetRootDir(ms.tempdir)
err := os.MkdirAll(filepath.Dir(dirs.SnapStateFile), 0755)
c.Assert(err, IsNil)
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
// create a fake systemd environment
os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)
ms.prevctlCmd = systemd.SystemctlCmd
systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
return []byte("ActiveState=inactive\n"), nil
}
ms.aa = testutil.MockCommand(c, "apparmor_parser", "")
ms.udev = testutil.MockCommand(c, "udevadm", "")
ms.umount = testutil.MockCommand(c, "umount", "")
ms.snapDiscardNs = testutil.MockCommand(c, "snap-discard-ns", "")
dirs.LibExecDir = ms.snapDiscardNs.BinDir()
ms.storeSigning = assertstest.NewStoreStack("can0nical", rootPrivKey, storePrivKey)
ms.restoreTrusted = sysdb.InjectTrusted(ms.storeSigning.Trusted)
ms.devAcct = assertstest.NewAccount(ms.storeSigning, "devdevev", map[string]interface{}{
"account-id": "devdevdev",
}, "")
err = ms.storeSigning.Add(ms.devAcct)
c.Assert(err, IsNil)
o, err := overlord.New()
c.Assert(err, IsNil)
ms.o = o
}
开发者ID:clobrano,项目名称:snappy,代码行数:34,代码来源:managers_test.go
示例3: TestHookTaskCorrectlyIncludesContext
func (s *hookManagerSuite) TestHookTaskCorrectlyIncludesContext(c *C) {
// Register a handler generator for the "test-hook" hook
mockHandler := hooktest.NewMockHandler()
mockHandlerGenerator := func(context *hookstate.Context) hookstate.Handler {
return mockHandler
}
// Force the snap command to exit with a failure and print to stderr so we
// can catch and verify it.
s.command = testutil.MockCommand(
c, "snap", ">&2 echo \"SNAP_CONTEXT=$SNAP_CONTEXT\"; exit 1")
s.manager.Register(regexp.MustCompile("test-hook"), mockHandlerGenerator)
s.manager.Ensure()
s.manager.Wait()
s.state.Lock()
defer s.state.Unlock()
c.Check(mockHandler.BeforeCalled, Equals, true)
c.Check(mockHandler.DoneCalled, Equals, false)
c.Check(mockHandler.ErrorCalled, Equals, true)
c.Check(s.task.Kind(), Equals, "run-hook")
c.Check(s.task.Status(), Equals, state.ErrorStatus)
c.Check(s.change.Status(), Equals, state.ErrorStatus)
checkTaskLogContains(c, s.task, regexp.MustCompile(".*SNAP_CONTEXT=\\S+"))
}
开发者ID:clobrano,项目名称:snappy,代码行数:29,代码来源:hookmgr_test.go
示例4: TestHookTaskCanKillHook
func (s *hookManagerSuite) TestHookTaskCanKillHook(c *C) {
// Force the snap command to hang
s.command = testutil.MockCommand(c, "snap", "while true; do sleep 1; done")
s.manager.Ensure()
completed := make(chan struct{})
go func() {
s.manager.Wait()
close(completed)
}()
// Abort the change, which should kill the hanging hook, and wait for the
// task to complete.
s.state.Lock()
s.change.Abort()
s.state.Unlock()
s.manager.Ensure()
<-completed
s.state.Lock()
defer s.state.Unlock()
c.Check(s.mockHandler.BeforeCalled, Equals, true)
c.Check(s.mockHandler.DoneCalled, Equals, false)
c.Check(s.mockHandler.ErrorCalled, Equals, true)
c.Check(s.mockHandler.Err, ErrorMatches, ".*hook \"configure\" aborted.*")
c.Check(s.task.Kind(), Equals, "run-hook")
c.Check(s.task.Status(), Equals, state.ErrorStatus)
c.Check(s.change.Status(), Equals, state.ErrorStatus)
checkTaskLogContains(c, s.task, `.*hook "configure" aborted.*`)
}
开发者ID:pedronis,项目名称:snappy,代码行数:32,代码来源:hookmgr_test.go
示例5: SetUpTest
func (s *createUserSuite) SetUpTest(c *check.C) {
s.mockHome = c.MkDir()
s.restorer = osutil.MockUserLookup(func(string) (*user.User, error) {
current, err := user.Current()
if err != nil {
c.Fatalf("user.Current() failed with %s", err)
}
return &user.User{
HomeDir: s.mockHome,
Gid: current.Gid,
Uid: current.Uid,
}, nil
})
s.mockAddUser = testutil.MockCommand(c, "adduser", "")
s.mockUserMod = testutil.MockCommand(c, "usermod", "")
}
开发者ID:pedronis,项目名称:snappy,代码行数:16,代码来源:user_test.go
示例6: TestHookTaskHandlerErrorError
func (s *hookManagerSuite) TestHookTaskHandlerErrorError(c *C) {
// Register a handler generator for the "test-hook" hook
mockHandler := hooktest.NewMockHandler()
mockHandler.ErrorError = true
mockHandlerGenerator := func(context *hookstate.Context) hookstate.Handler {
return mockHandler
}
// Force the snap command to simply exit 1, so the handler Error() runs
s.command = testutil.MockCommand(c, "snap", "exit 1")
s.manager.Register(regexp.MustCompile("test-hook"), mockHandlerGenerator)
s.manager.Ensure()
s.manager.Wait()
s.state.Lock()
defer s.state.Unlock()
c.Check(mockHandler.BeforeCalled, Equals, true)
c.Check(mockHandler.DoneCalled, Equals, false)
c.Check(mockHandler.ErrorCalled, Equals, true)
c.Check(s.task.Kind(), Equals, "run-hook")
c.Check(s.task.Status(), Equals, state.ErrorStatus)
c.Check(s.change.Status(), Equals, state.ErrorStatus)
checkTaskLogContains(c, s.task, regexp.MustCompile(".*Error failed at user request.*"))
}
开发者ID:clobrano,项目名称:snappy,代码行数:28,代码来源:hookmgr_test.go
示例7: TestUnloadProfileReportsErrors
func (s *appArmorSuite) TestUnloadProfileReportsErrors(c *C) {
cmd := testutil.MockCommand(c, "apparmor_parser", "exit 42")
defer cmd.Restore()
err := apparmor.UnloadProfile("snap.samba.smbd")
c.Assert(err.Error(), Equals, `cannot unload apparmor profile: exit status 42
apparmor_parser output:
`)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:8,代码来源:apparmor_test.go
示例8: TestLoadProfileRunsAppArmorParserReplace
func (s *appArmorSuite) TestLoadProfileRunsAppArmorParserReplace(c *C) {
cmd := testutil.MockCommand(c, "apparmor_parser", "")
defer cmd.Restore()
err := apparmor.LoadProfile("/path/to/snap.samba.smbd")
c.Assert(err, IsNil)
c.Assert(cmd.Calls(), DeepEquals, [][]string{
{"apparmor_parser", "--replace", "--write-cache", "-O", "no-expr-simplify", "--cache-loc=/var/cache/apparmor", "/path/to/snap.samba.smbd"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:9,代码来源:apparmor_test.go
示例9: TestUnloadProfileRunsAppArmorParserRemove
func (s *appArmorSuite) TestUnloadProfileRunsAppArmorParserRemove(c *C) {
cmd := testutil.MockCommand(c, "apparmor_parser", "")
defer cmd.Restore()
err := apparmor.UnloadProfile("snap.samba.smbd")
c.Assert(err, IsNil)
c.Assert(cmd.Calls(), DeepEquals, [][]string{
{"apparmor_parser", "--remove", "snap.samba.smbd"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:9,代码来源:apparmor_test.go
示例10: TestReloadUDevRulesRunsUDevAdm
func (s *uDevSuite) TestReloadUDevRulesRunsUDevAdm(c *C) {
cmd := testutil.MockCommand(c, "udevadm", "")
defer cmd.Restore()
err := udev.ReloadRules()
c.Assert(err, IsNil)
c.Assert(cmd.Calls(), DeepEquals, [][]string{
{"udevadm", "control", "--reload-rules"},
{"udevadm", "trigger"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:10,代码来源:udev_test.go
示例11: TestLoadProfileReportsErrors
func (s *appArmorSuite) TestLoadProfileReportsErrors(c *C) {
cmd := testutil.MockCommand(c, "apparmor_parser", "exit 42")
defer cmd.Restore()
err := apparmor.LoadProfile("/path/to/snap.samba.smbd")
c.Assert(err.Error(), Equals, `cannot load apparmor profile: exit status 42
apparmor_parser output:
`)
c.Assert(cmd.Calls(), DeepEquals, [][]string{
{"apparmor_parser", "--replace", "--write-cache", "-O", "no-expr-simplify", "--cache-loc=/var/cache/apparmor", "/path/to/snap.samba.smbd"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:11,代码来源:apparmor_test.go
示例12: TestFuseInContainer
func (s *SystemdTestSuite) TestFuseInContainer(c *C) {
if !osutil.FileExists("/dev/fuse") {
c.Skip("No /dev/fuse on the system")
}
systemdCmd := testutil.MockCommand(c, "systemd-detect-virt", `
echo lxc
exit 0
`)
defer systemdCmd.Restore()
fuseCmd := testutil.MockCommand(c, "squashfuse", `
exit 0
`)
defer fuseCmd.Restore()
mockSnapPath := filepath.Join(c.MkDir(), "/var/lib/snappy/snaps/foo_1.0.snap")
err := os.MkdirAll(filepath.Dir(mockSnapPath), 0755)
c.Assert(err, IsNil)
err = ioutil.WriteFile(mockSnapPath, nil, 0644)
c.Assert(err, IsNil)
mountUnitName, err := New("", nil).WriteMountUnitFile("foo", mockSnapPath, "/apps/foo/1.0", "squashfs")
c.Assert(err, IsNil)
defer os.Remove(mountUnitName)
mount, err := ioutil.ReadFile(filepath.Join(dirs.SnapServicesDir, mountUnitName))
c.Assert(err, IsNil)
c.Assert(string(mount), Equals, fmt.Sprintf(`[Unit]
Description=Mount unit for foo
[Mount]
What=%s
Where=/apps/foo/1.0
Type=fuse.squashfuse
Options=ro,allow_other
[Install]
WantedBy=multi-user.target
`, mockSnapPath))
}
开发者ID:mvo5,项目名称:snappy,代码行数:41,代码来源:systemd_test.go
示例13: SetUpTest
func (s *setupSuite) SetUpTest(c *C) {
dirs.SetRootDir(c.MkDir())
err := os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "etc", "systemd", "system", "multi-user.target.wants"), 0755)
c.Assert(err, IsNil)
s.prevctlCmd = systemd.SystemctlCmd
systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
return []byte("ActiveState=inactive\n"), nil
}
s.umount = testutil.MockCommand(c, "umount", "")
}
开发者ID:clobrano,项目名称:snappy,代码行数:12,代码来源:setup_test.go
示例14: SetUpTest
func (s *backendSuite) SetUpTest(c *C) {
s.Backend = &udev.Backend{}
s.BackendSuite.SetUpTest(c)
// Mock away any real udev interaction
s.udevadmCmd = testutil.MockCommand(c, "udevadm", "")
// Prepare a directory for udev rules
// NOTE: Normally this is a part of the OS snap.
err := os.MkdirAll(dirs.SnapUdevRulesDir, 0700)
c.Assert(err, IsNil)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:12,代码来源:backend_test.go
示例15: TestDiscardNamespaceMntFileAbsent
func (s *nsSuite) TestDiscardNamespaceMntFileAbsent(c *C) {
// Mock the snap-discard-ns command
cmd := testutil.MockCommand(c, "snap-discard-ns", "")
dirs.LibExecDir = cmd.BinDir()
defer cmd.Restore()
// don't create the .mnt file that triggers the discard operation
// ask the backend to discard the namespace
err := s.be.DiscardSnapNamespace("snap-name")
c.Assert(err, IsNil)
c.Check(cmd.Calls(), IsNil)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:13,代码来源:ns_test.go
示例16: SetUpTest
func (s *backendSuite) SetUpTest(c *C) {
s.Backend = &apparmor.Backend{}
s.BackendSuite.SetUpTest(c)
// Prepare a directory for apparmor profiles.
// NOTE: Normally this is a part of the OS snap.
err := os.MkdirAll(dirs.SnapAppArmorDir, 0700)
c.Assert(err, IsNil)
err = os.MkdirAll(dirs.AppArmorCacheDir, 0700)
c.Assert(err, IsNil)
// Mock away any real apparmor interaction
s.parserCmd = testutil.MockCommand(c, "apparmor_parser", fakeAppArmorParser)
}
开发者ID:clobrano,项目名称:snappy,代码行数:13,代码来源:backend_test.go
示例17: TestDiscardNamespaceMntFilePresent
func (s *nsSuite) TestDiscardNamespaceMntFilePresent(c *C) {
// Mock the snap-discard-ns command
cmd := testutil.MockCommand(c, "snap-discard-ns", "")
dirs.LibExecDir = cmd.BinDir()
defer cmd.Restore()
// the presence of the .mnt file is the trigger so create it now
c.Assert(os.MkdirAll(dirs.SnapRunNsDir, 0755), IsNil)
c.Assert(ioutil.WriteFile(filepath.Join(dirs.SnapRunNsDir, "snap-name.mnt"), nil, 0644), IsNil)
err := s.be.DiscardSnapNamespace("snap-name")
c.Assert(err, IsNil)
c.Check(cmd.Calls(), DeepEquals, [][]string{{"snap-discard-ns", "snap-name"}})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:ns_test.go
示例18: TestModprobeCall
func (s *kmodSuite) TestModprobeCall(c *C) {
cmd := testutil.MockCommand(c, "modprobe", "")
defer cmd.Restore()
err := kmod.LoadModules([]string{
"module1",
"module2",
})
c.Assert(err, IsNil)
c.Assert(cmd.Calls(), DeepEquals, [][]string{
{"modprobe", "--syslog", "module1"},
{"modprobe", "--syslog", "module2"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:kmod_test.go
示例19: TestDiscardNamespaceSilentFailure
func (s *nsSuite) TestDiscardNamespaceSilentFailure(c *C) {
// Mock the snap-discard-ns command, make it fail
cmd := testutil.MockCommand(c, "snap-discard-ns", "exit 1")
dirs.LibExecDir = cmd.BinDir()
defer cmd.Restore()
// the presence of the .mnt file is the trigger so create it now
c.Assert(os.MkdirAll(dirs.SnapRunNsDir, 0755), IsNil)
c.Assert(ioutil.WriteFile(filepath.Join(dirs.SnapRunNsDir, "snap-name.mnt"), nil, 0644), IsNil)
// ask the backend to discard the namespace
err := s.be.DiscardSnapNamespace("snap-name")
c.Assert(err, ErrorMatches, `cannot discard preserved namespaces of snap "snap-name": exit status 1`)
c.Check(cmd.Calls(), DeepEquals, [][]string{{"snap-discard-ns", "snap-name"}})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:15,代码来源:ns_test.go
示例20: TestUnloadRemovesCachedProfile
func (s *appArmorSuite) TestUnloadRemovesCachedProfile(c *C) {
cmd := testutil.MockCommand(c, "apparmor_parser", "")
defer cmd.Restore()
dirs.SetRootDir(c.MkDir())
defer dirs.SetRootDir("")
err := os.MkdirAll(dirs.AppArmorCacheDir, 0755)
c.Assert(err, IsNil)
fname := filepath.Join(dirs.AppArmorCacheDir, "profile")
ioutil.WriteFile(fname, []byte("blob"), 0600)
err = apparmor.UnloadProfile("profile")
c.Assert(err, IsNil)
_, err = os.Stat(fname)
c.Check(os.IsNotExist(err), Equals, true)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:16,代码来源:apparmor_test.go
注:本文中的github.com/snapcore/snapd/testutil.MockCommand函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论