• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cli.ExecCommandErr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ubuntu-core/snappy/integration-tests/testutils/cli.ExecCommandErr函数的典型用法代码示例。如果您正苦于以下问题:Golang ExecCommandErr函数的具体用法?Golang ExecCommandErr怎么用?Golang ExecCommandErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ExecCommandErr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: tearDownSnapd

func tearDownSnapd(fromBranch bool) error {
	if _, err := cli.ExecCommandErr("sudo", "systemctl", "stop",
		"snapd.service"); err != nil {
		return err
	}

	if _, err := cli.ExecCommandErr("sudo", "rm", "-rf", cfgDir); err != nil {
		return err
	}

	if fromBranch {
		if _, err := cli.ExecCommandErr("sudo", "umount", daemonBinaryPath); err != nil {
			return err
		}
	}

	if _, err := cli.ExecCommandErr("sudo", "systemctl", "daemon-reload"); err != nil {
		return err
	}

	if _, err := cli.ExecCommandErr("sudo", "systemctl", "start",
		"snapd.service"); err != nil {
		return err
	}

	return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:27,代码来源:base_test.go


示例2: TestPurgeRemovesDataForDeactivatedNotRemovedPackage

func (s *purgeSuite) TestPurgeRemovesDataForDeactivatedNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)
	_, err := cli.ExecCommandErr("sudo", "snappy", "deactivate", snap)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(snapDataPath)
	c.Assert(os.IsNotExist(err), check.Equals, true)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:11,代码来源:purge_test.go


示例3: TestPurgeHonoursInstalledFlagForNotRemovedPackage

func (s *purgeSuite) TestPurgeHonoursInstalledFlagForNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)

	dataFile := filepath.Join(snapDataPath, "data")
	_, err := cli.ExecCommandErr("sudo", "touch", dataFile)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap, "--installed")
	c.Assert(err, check.IsNil)

	_, err = os.Stat(dataFile)
	c.Assert(os.IsNotExist(err), check.Equals, true, check.Commentf("Error %v instead of os.IsNotExist", err))

	_, err = os.Stat(snapDataPath)
	c.Assert(err, check.IsNil)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:16,代码来源:purge_test.go


示例4: RemoveSnap

// RemoveSnap executes the required command to remove the specified snap
func RemoveSnap(c *check.C, packageName string) string {
	cli.ExecCommand(c, "sudo", "snap", "remove", packageName)
	// XXX: right now "snap list" on freshly booted is empty
	// because u-d-f installed aren't in state
	out, _ := cli.ExecCommandErr("snap", "list")
	return out
}
开发者ID:dholbach,项目名称:snappy,代码行数:8,代码来源:common.go


示例5: removeSnap

func removeSnap(c *check.C, packageName string) string {
	cli.ExecCommand(c, "sudo", "snap", "remove", packageName)
	// FIXME: should `snap remove` shold show a list afterards?
	//        like `snappy install`?
	// right now "snap list" on freshly booted is empty
	// because u-d-f installed aren't in state
	out, _ := cli.ExecCommandErr("snap", "list")
	return out
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:snap_example_test.go


示例6: TestDestroyUnexistingClassicMustPrintError

func (s *classicDimensionSuite) TestDestroyUnexistingClassicMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snap", "destroy-classic")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to destroy unexisting classic dimension did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"error: Classic dimension is not enabled.\n",
		check.Commentf("Wrong error message"))
}
开发者ID:dholbach,项目名称:snappy,代码行数:9,代码来源:classic_dimension_test.go


示例7: TestPurgeReturnsErrorForNotRemovedPackage

func (s *purgeSuite) TestPurgeReturnsErrorForNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)

	_, err := cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.NotNil)

	_, err = os.Stat(snapDataPath)
	c.Assert(err, check.IsNil)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:9,代码来源:purge_test.go


示例8: TestCallFailBinaryFromInstalledSnap

func (s *installAppSuite) TestCallFailBinaryFromInstalledSnap(c *check.C) {
	snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
	defer os.Remove(snapPath)
	c.Assert(err, check.IsNil, check.Commentf("Error building local snap: %s", err))
	common.InstallSnap(c, snapPath)
	defer common.RemoveSnap(c, data.BasicBinariesSnapName)

	_, err = cli.ExecCommandErr("basic-binaries.fail")
	c.Assert(err, check.NotNil, check.Commentf("The binary did not fail"))
}
开发者ID:General-Beck,项目名称:snappy,代码行数:10,代码来源:installApp_test.go


示例9: TestInstallUnexistingAppMustPrintError

func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snappy", "install", "unexisting.canonical")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to install an unexisting snap did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"Installing unexisting.canonical\n"+
			"unexisting.canonical failed to install: snappy package not found\n",
		check.Commentf("Wrong error message"))
}
开发者ID:alecu,项目名称:snappy,代码行数:10,代码来源:installApp_test.go


示例10: TestInstallUnexistingAppMustPrintError

func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snap", "install", "unexisting.canonical")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to install an unexisting snap did not exit with an error"))
	c.Assert(string(output), testutil.Contains,
		"error: cannot perform the following tasks:\n"+
			"- Download snap \"unexisting.canonical\" from channel \"stable\" (snap not found)\n",
		check.Commentf("Wrong error message"))
}
开发者ID:dholbach,项目名称:snappy,代码行数:10,代码来源:installApp_test.go


示例11: determinePayload

func determinePayload(payload string) (string, error) {
	if _, err := os.Stat(payload); err == nil {
		// payload is a file, in order to make the snap file available to http we need to move it to its $SNAP_DATA path
		snapAppDataPath := filepath.Join("/var/lib/snaps", httpClientSnap, "current")
		if _, err := cli.ExecCommandErr("sudo", "cp", payload, snapAppDataPath); err != nil {
			return "", err
		}
		return "@" + filepath.Join(snapAppDataPath, filepath.Base(payload)), nil
	}
	// payload is a string
	return payload, nil
}
开发者ID:alecu,项目名称:snappy,代码行数:12,代码来源:snapd_test.go


示例12: TestReEnableClassicMustPrintError

func (s *classicDimensionSuite) TestReEnableClassicMustPrintError(c *check.C) {
	c.Skip("Skipping until LP: #1563193 is fixed")
	s.enableClassic(c)
	defer s.destroyClassic(c)
	output, err := cli.ExecCommandErr("sudo", "snap", "enable-classic")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to re-enable classic dimension did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"Classic dimension is already enabled.\n",
		check.Commentf("Wrong error message"))
}
开发者ID:dholbach,项目名称:snappy,代码行数:12,代码来源:classic_dimension_test.go


示例13: TestDeactivateRemovesBinary

func (s *activateSuite) TestDeactivateRemovesBinary(c *check.C) {
	cli.ExecCommand(c, "sudo", "snappy", "deactivate", activateSnapName)
	defer cli.ExecCommand(c, "sudo", "snappy", "activate", activateSnapName)
	output, err := cli.ExecCommandErr(activateBinName)

	c.Assert(err, check.NotNil, check.Commentf("Deactivated snap binary did not exit with an error"))
	c.Assert(output, check.Not(check.Equals), activateEchoOutput,
		check.Commentf("Deactivated snap binary was not removed"))

	list := cli.ExecCommand(c, "snappy", "list", "-v")

	c.Assert(list, check.Matches, deActivatedPattern)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:13,代码来源:activate_test.go


示例14: setUpSnapd

func setUpSnapd(c *check.C, fromBranch bool, extraEnv string) {
	cli.ExecCommand(c, "sudo", "systemctl", "stop",
		"snapd.service", "snapd.socket")

	if fromBranch {
		binPath, err := filepath.Abs("integration-tests/bin/snapd")
		c.Assert(err, check.IsNil)

		_, err = cli.ExecCommandErr("sudo", "mount", "-o", "bind",
			binPath, daemonBinaryPath)
		c.Assert(err, check.IsNil)
	}

	err := writeEnvConfig(extraEnv)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "systemctl", "daemon-reload")
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "systemctl", "start", "snapd.service")
	c.Assert(err, check.IsNil)
}
开发者ID:dholbach,项目名称:snappy,代码行数:22,代码来源:base_test.go


示例15: TestPurgeRemovesDataFromRemovedPackage

func (s *purgeSuite) TestPurgeRemovesDataFromRemovedPackage(c *check.C) {
	common.RemoveSnap(c, data.BasicSnapName)

	versionSnapDataPath, err := getVersionSnapDataPath(snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(versionSnapDataPath)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(versionSnapDataPath)
	c.Assert(os.IsNotExist(err), check.Equals, true)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:15,代码来源:purge_test.go


示例16: writeEnvConfig

func writeEnvConfig(extraEnv string) error {
	if _, err := cli.ExecCommandErr("sudo", "mkdir", "-p", cfgDir); err != nil {
		return err
	}

	cfgFile := filepath.Join(cfgDir, "env.conf")
	// FIXME: for now pass a test-only trusted key through an env var
	trustedKey, err := filepath.Abs("integration-tests/data/trusted.acckey")
	if err != nil {
		return err
	}

	cfgContent := []byte(fmt.Sprintf(`[Service]
Environment="SNAPPY_TRUSTED_ACCOUNT_KEY=%s" "%s"
`, trustedKey, extraEnv))
	if err = ioutil.WriteFile("/tmp/snapd.env.conf", cfgContent, os.ModeExclusive); err != nil {
		return err
	}

	if _, err = cli.ExecCommandErr("sudo", "mv", "/tmp/snapd.env.conf", cfgFile); err != nil {
		return err
	}
	return nil
}
开发者ID:dholbach,项目名称:snappy,代码行数:24,代码来源:base_test.go


示例17: GetCurrentVersion

// GetCurrentVersion returns the version of the installed and active package.
func GetCurrentVersion(c *check.C, packageName string) string {
	output, err := cli.ExecCommandErr("snap", "list")
	if err != nil {
		// XXX: right now "snap list" on freshly booted is empty
		// because u-d-f installed aren't in state
		return "verUnknown"
	}
	pattern := "(?mU)^" + packageName + " +(.*)$"
	re := regexp.MustCompile(pattern)
	match := re.FindStringSubmatch(string(output))
	c.Assert(match, check.NotNil, check.Commentf("Version of %s not found in %s", packageName, output))

	// match is like "ubuntu-core   2015-06-18 93        ubuntu"
	items := strings.Fields(match[0])
	return items[2]
}
开发者ID:dholbach,项目名称:snappy,代码行数:17,代码来源:common.go


示例18: TestGrubBootDirMustNotContainKernelFiles

func (s *grubSuite) TestGrubBootDirMustNotContainKernelFiles(c *check.C) {
	bootSystem, err := partition.BootSystem()
	c.Assert(err, check.IsNil, check.Commentf("Error getting boot system: %s", err))

	if bootSystem != "grub" {
		c.Skip("This test checks properties of grub based systems")
	}

	bootDir := partition.BootDir(bootSystem)
	for _, targetFile := range []string{"vmlinuz", "initrd.img"} {
		output, err := cli.ExecCommandErr("find", bootDir, "-name", fmt.Sprintf(`"%s"`, targetFile))

		c.Check(err, check.IsNil)
		c.Check(output, check.Equals, "")
	}
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:16,代码来源:grub_test.go


示例19: TestCallHelloWorldEvilMustPrintPermissionDeniedError

func (s *helloWorldExampleSuite) TestCallHelloWorldEvilMustPrintPermissionDeniedError(c *check.C) {
	common.InstallSnap(c, "hello-world/edge")
	s.AddCleanup(func() {
		common.RemoveSnap(c, "hello-world")
	})

	echoOutput, err := cli.ExecCommandErr("hello-world.evil")
	c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))

	expected := "" +
		"Hello Evil World!\n" +
		"This example demonstrates the app confinement\n" +
		"You should see a permission denied error next\n" +
		"/snaps/hello-world.canonical/.*/bin/evil: \\d+: " +
		"/snaps/hello-world.canonical/.*/bin/evil: " +
		"cannot create /var/tmp/myevil.txt: Permission denied\n"

	c.Assert(string(echoOutput), check.Matches, expected)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:19,代码来源:examples_test.go


示例20: makeRequest

// makeRequest makes a request to the API according to the provided options.
func makeRequest(options *requestOptions) (body []byte, err error) {
	cmd := []string{"sudo", "http.do",
		"--pretty", "none",
		"--body",
		"--ignore-stdin",
		options.verb, options.resource}

	if options.payload != "" {
		payload, err := determinePayload(options.payload)
		if err != nil {
			return nil, err
		}
		if strings.HasPrefix(payload, "@") {
			defer os.Remove(payload[1:])
		}
		cmd = append(cmd, payload)
	}

	bodyString, err := cli.ExecCommandErr(append(cmd, "X-Allow-Unsigned:1")...)

	return []byte(bodyString), err
}
开发者ID:alecu,项目名称:snappy,代码行数:23,代码来源:snapd_test.go



注:本文中的github.com/ubuntu-core/snappy/integration-tests/testutils/cli.ExecCommandErr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang common.InstallSnap函数代码示例发布时间:2022-05-28
下一篇:
Golang cli.ExecCommand函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap