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

Golang testing.PatchExecutable函数代码示例

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

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



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

示例1: TestRebootWithMissbehavingContainers

func (s *RebootSuite) TestRebootWithMissbehavingContainers(c *gc.C) {
	testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript)
	testing.PatchExecutable(c, s, "lxc-info", lxcInfoScriptMissbehave)

	s.PatchValue(reboot.Timeout, time.Duration(1*time.Second))
	w, err := reboot.NewRebootWaiter(s.st, s.acfg)
	c.Assert(err, jc.ErrorIsNil)

	err = w.ExecuteReboot(params.ShouldReboot)
	c.Assert(err, gc.ErrorMatches, "Timeout reached waiting for containers to shutdown")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:11,代码来源:reboot_nix_test.go


示例2: TestRebootWithContainers

func (s *RebootSuite) TestRebootWithContainers(c *gc.C) {
	testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript)
	testing.PatchExecutable(c, s, "lxc-info", lxcInfoScript)
	expectedRebootParams := s.rebootCommandParams(c)

	s.PatchValue(reboot.Timeout, time.Duration(5*time.Second))
	w, err := reboot.NewRebootWaiter(s.st, s.acfg)
	c.Assert(err, jc.ErrorIsNil)

	err = w.ExecuteReboot(params.ShouldReboot)
	c.Assert(err, jc.ErrorIsNil)
	testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...)
	ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:reboot_nix_test.go


示例3: setupContainerWorker

func (s *ContainerSetupSuite) setupContainerWorker(c *gc.C, tag names.MachineTag) (worker.StringsWatchHandler, worker.Runner) {
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	runner := worker.NewRunner(allFatal, noImportance)
	pr := s.st.Provisioner()
	machine, err := pr.Machine(tag)
	c.Assert(err, jc.ErrorIsNil)
	err = machine.SetSupportedContainers(instance.ContainerTypes...)
	c.Assert(err, jc.ErrorIsNil)
	cfg := s.AgentConfigForTag(c, tag)

	watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
	params := provisioner.ContainerSetupParams{
		Runner:              runner,
		WorkerName:          watcherName,
		SupportedContainers: instance.ContainerTypes,
		ImageURLGetter:      &containertesting.MockURLGetter{},
		Machine:             machine,
		Provisioner:         pr,
		Config:              cfg,
		InitLock:            s.initLock,
	}
	handler := provisioner.NewContainerSetupHandler(params)
	runner.StartWorker(watcherName, func() (worker.Worker, error) {
		return worker.NewStringsWorker(handler), nil
	})
	return handler, runner
}
开发者ID:chrisjohnston,项目名称:juju,代码行数:27,代码来源:container_initialisation_test.go


示例4: SetUpTest

func (s *MongoSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)

	s.mongodVersion = mongo.Mongo24

	testing.PatchExecutable(c, s, "mongod", "#!/bin/bash\n\nprintf %s 'db version v2.4.9'\n")
	jujuMongodPath, err := exec.LookPath("mongod")
	c.Assert(err, jc.ErrorIsNil)

	s.PatchValue(&mongo.JujuMongod24Path, jujuMongodPath)
	s.mongodPath = jujuMongodPath

	// Patch "df" such that it always reports there's 1MB free.
	s.PatchValue(mongo.AvailSpace, func(dir string) (float64, error) {
		info, err := os.Stat(dir)
		if err != nil {
			return 0, err
		}
		if info.IsDir() {
			return 1, nil

		}
		return 0, fmt.Errorf("not a directory")
	})
	s.PatchValue(mongo.MinOplogSizeMB, 1)

	testPath := c.MkDir()
	s.mongodConfigPath = filepath.Join(testPath, "mongodConfig")
	s.PatchValue(mongo.MongoConfigPath, s.mongodConfigPath)

	s.data = svctesting.NewFakeServiceData()
	mongo.PatchService(s.PatchValue, s.data)
}
开发者ID:xushiwei,项目名称:juju,代码行数:33,代码来源:mongo_test.go


示例5: TestFsAvailSpaceErrors

func (s *preallocSuite) TestFsAvailSpaceErrors(c *gc.C) {
	tests := []struct {
		desc   string
		output string
		err    string
	}{{
		desc: "result is non-numeric",
		output: `Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/vda1        8124856 1365292       abc  18% /`,
		err: `strconv.ParseInt: parsing "abc": invalid syntax`,
	}, {
		desc:   "not enough lines",
		output: "abc",
		err:    `could not determine available space on ""`,
	}, {
		desc:   "not enough fields on second line",
		output: "abc\ndef",
		err:    `could not determine available space on ""`,
	}}
	for i, test := range tests {
		c.Logf("test %d: %s", i, test.desc)
		testing.PatchExecutable(c, s, "df", "#!/bin/sh\ncat<<EOF\n"+test.output+"\nEOF")
		_, err := mongo.FsAvailSpace("")
		c.Check(err, gc.ErrorMatches, test.err)
	}
}
开发者ID:jiasir,项目名称:juju,代码行数:26,代码来源:prealloc_test.go


示例6: SetUpTest

func (s *ListBlockDevicesSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.PatchValue(diskmanager.BlockDeviceInUse, func(storage.BlockDevice) (bool, error) {
		return false, nil
	})
	testing.PatchExecutable(c, s, "udevadm", `#!/bin/bash --norc`)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:7,代码来源:lsblk_test.go


示例7: TestInstallMongodFallsBack

func (s *MongoSuite) TestInstallMongodFallsBack(c *gc.C) {
	if runtime.GOOS == "windows" {
		c.Skip("Skipping TestInstallMongodFallsBack as mongo is not installed on windows")
	}

	type installs struct {
		series string
		cmd    string
	}

	tests := []installs{
		{"precise", "mongodb-server"},
		{"trusty", "juju-mongodb3.2\njuju-mongodb"},
		{"wily", "juju-mongodb3.2\njuju-mongodb"},
		{"xenial", "juju-mongodb3.2\njuju-mongodb"},
	}

	dataDir := c.MkDir()
	outputFile := filepath.Join(dataDir, "apt-get-args")
	testing.PatchExecutable(c, s, "apt-get", fmt.Sprintf(fakeInstallScript, outputFile))
	for _, test := range tests {
		c.Logf("Testing mongo install for series: %s", test.series)
		s.patchSeries(test.series)
		err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
		c.Assert(err, jc.ErrorIsNil)

		args, err := ioutil.ReadFile(outputFile)
		c.Assert(err, jc.ErrorIsNil)
		c.Check(strings.TrimSpace(string(args)), gc.Equals, test.cmd)

		err = os.Remove(outputFile)
		c.Assert(err, jc.ErrorIsNil)
	}
}
开发者ID:xushiwei,项目名称:juju,代码行数:34,代码来源:mongo_test.go


示例8: TestDownloadFetchesAndCaches

func (s *imageSuite) TestDownloadFetchesAndCaches(c *gc.C) {
	// Set up some image data for a fake server.
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	useTestImageData(map[string]string{
		"/trusty-released-amd64-root.tar.gz": testImageData,
		"/SHA256SUMS":                        testImageChecksum + " *trusty-released-amd64-root.tar.gz",
	})
	defer func() {
		useTestImageData(nil)
	}()

	// The image is not in imagestorage, so the download request causes
	// the API server to search for the image on cloud-images, fetches it,
	// and then cache it in imagestorage.
	url := s.imageURL(c, "lxc", "trusty", "amd64")
	response := s.downloadRequest(c, url)
	data := s.testDownload(c, response)

	metadata, cachedData := s.getImageFromStorage(c, s.State, "lxc", "trusty", "amd64")
	c.Assert(metadata.Size, gc.Equals, int64(len(testImageData)))
	c.Assert(metadata.SHA256, gc.Equals, testImageChecksum)
	c.Assert(metadata.SourceURL, gc.Equals, "test://cloud-images/trusty-released-amd64-root.tar.gz")
	c.Assert(string(data), gc.Equals, string(testImageData))
	c.Assert(string(data), gc.Equals, string(cachedData))
}
开发者ID:pmatulis,项目名称:juju,代码行数:25,代码来源:images_test.go


示例9: TestSetupRoutesAndIPTablesIPTablesAddError

func (s *lxcBrokerSuite) TestSetupRoutesAndIPTablesIPTablesAddError(c *gc.C) {
	// Isolate the test from the host machine. Patch iptables with a
	// script which returns code=1 for the check but fails when adding
	// the rule.
	script := `if [[ "$3" == "-C" ]]; then exit 1; else exit 42; fi`
	gitjujutesting.PatchExecutable(c, s, "iptables", script)
	gitjujutesting.PatchExecutableThrowError(c, s, "ip", 123)

	fakeptablesRules := map[string]provisioner.IptablesRule{
		"IPTablesSNAT": {
			"nat",
			"POSTROUTING",
			"{{.HostIF}} {{.HostIP}}",
		},
	}
	s.PatchValue(provisioner.IptablesRules, fakeptablesRules)

	ifaceInfo := []network.InterfaceInfo{{
		Address: network.NewAddress("0.1.2.3"),
	}}

	addr := network.NewAddress("0.1.2.1")
	err := provisioner.SetupRoutesAndIPTables("nic", addr, "bridge", ifaceInfo, false)
	c.Assert(err, gc.ErrorMatches, `command "iptables -t nat -I .*" failed with exit code 42`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:25,代码来源:lxc-broker_test.go


示例10: TestFsAvailSpace

func (s *preallocSuite) TestFsAvailSpace(c *gc.C) {
	output := `Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/vda1        8124856 1365292     12345  18% /`
	testing.PatchExecutable(c, s, "df", "#!/bin/sh\ncat<<EOF\n"+output+"\nEOF")

	mb, err := mongo.FsAvailSpace("")
	c.Assert(err, gc.IsNil)
	c.Assert(mb, gc.Equals, float64(12345)/1024)
}
开发者ID:jiasir,项目名称:juju,代码行数:9,代码来源:prealloc_test.go


示例11: TestControllerInstancesInternal

func (s *controllerInstancesSuite) TestControllerInstancesInternal(c *gc.C) {
	// Patch os.Args so it appears that we're running in "jujud".
	s.PatchValue(&os.Args, []string{"/some/where/containing/jujud", "whatever"})
	// Patch the ssh executable so that it would cause an error if we
	// were to call it.
	testing.PatchExecutable(c, s, "ssh", "#!/bin/sh\nhead -n1 > /dev/null; echo abc >&2; exit 1")
	instances, err := s.env.ControllerInstances("not-used")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(instances, gc.DeepEquals, []instance.Id{BootstrapInstanceId})
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:environ_test.go


示例12: TestStateServerInstancesInternal

func (s *stateServerInstancesSuite) TestStateServerInstancesInternal(c *gc.C) {
	// If use-sshstorage=false, then we're on the bootstrap host;
	// verification is elided.
	env, err := manualProvider{}.Open(MinimalConfig(c))
	c.Assert(err, jc.ErrorIsNil)

	testing.PatchExecutable(c, s, "ssh", "#!/bin/sh\nhead -n1 > /dev/null; echo abc >&2; exit 1")
	instances, err := env.StateServerInstances()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(instances, gc.DeepEquals, []instance.Id{BootstrapInstanceId})
}
开发者ID:kakamessi99,项目名称:juju,代码行数:11,代码来源:environ_test.go


示例13: testListBlockDevicesExtended

func (s *ListBlockDevicesSuite) testListBlockDevicesExtended(
	c *gc.C,
	udevadmInfo string,
	expect storage.BlockDevice,
) {
	testing.PatchExecutable(c, s, "lsblk", `#!/bin/bash --norc
cat <<EOF
KNAME="sda" SIZE="240057409536" LABEL="" UUID="" TYPE="disk"
EOF`)
	testing.PatchExecutable(c, s, "udevadm", `#!/bin/bash --norc
cat <<EOF
`+strings.TrimSpace(udevadmInfo)+`
EOF`)

	expect.DeviceName = "sda"
	expect.Size = 228936

	devices, err := diskmanager.ListBlockDevices()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(devices, jc.DeepEquals, []storage.BlockDevice{expect})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:21,代码来源:lsblk_test.go


示例14: TestListBlockDevicesDeviceNotExist

func (s *ListBlockDevicesSuite) TestListBlockDevicesDeviceNotExist(c *gc.C) {
	s.PatchValue(diskmanager.BlockDeviceInUse, func(dev storage.BlockDevice) (bool, error) {
		return false, os.ErrNotExist
	})
	testing.PatchExecutable(c, s, "lsblk", `#!/bin/bash --norc
cat <<EOF
KNAME="sda" SIZE="240057409536" LABEL="" UUID="" TYPE="disk"
KNAME="sdb" SIZE="32017047552" LABEL="" UUID="" TYPE="disk"
EOF`)

	devices, err := diskmanager.ListBlockDevices()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(devices, gc.HasLen, 0)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:14,代码来源:lsblk_test.go


示例15: TestDownloadFetchNoSHA256File

func (s *imageSuite) TestDownloadFetchNoSHA256File(c *gc.C) {
	// Set up some image data for a fake server.
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	useTestImageData(map[string]string{
		"/trusty-released-amd64-root.tar.gz": testImageData,
	})
	defer func() {
		useTestImageData(nil)
	}()

	resp := s.downloadRequest(c, s.imageURL(c, "lxc", "trusty", "amd64"))
	defer resp.Body.Close()
	s.assertErrorResponse(c, resp, http.StatusInternalServerError, ".* cannot find sha256 checksum .*")
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:images_test.go


示例16: TestDownloadFetchChecksumMismatch

func (s *imageSuite) TestDownloadFetchChecksumMismatch(c *gc.C) {
	// Set up some image data for a fake server.
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	useTestImageData(map[string]string{
		"/trusty-released-amd64-root.tar.gz": s.imageData,
		"/SHA256SUMS":                        "different-checksum *trusty-released-amd64-root.tar.gz",
	})
	defer func() {
		useTestImageData(nil)
	}()

	resp, err := s.downloadRequest(c, s.imageURL(c, "lxc", "trusty", "amd64"))
	defer resp.Body.Close()
	c.Assert(err, gc.IsNil)
	s.assertErrorResponse(c, resp, http.StatusInternalServerError, ".* download checksum mismatch .*")
}
开发者ID:Pankov404,项目名称:juju,代码行数:16,代码来源:images_test.go


示例17: TestDownloadFetchesAndCachesConcurrent

func (s *imageSuite) TestDownloadFetchesAndCachesConcurrent(c *gc.C) {
	// Set up some image data for a fake server.
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	useTestImageData(map[string]string{
		"/trusty-released-amd64-root.tar.gz": s.imageData,
		"/SHA256SUMS":                        s.imageChecksum + " *trusty-released-amd64-root.tar.gz",
	})
	defer func() {
		useTestImageData(nil)
	}()

	// Fetch the same image multiple times concurrently and ensure that
	// it is only downloaded from the external URL once.
	done := make(chan struct{})
	go func() {
		var wg sync.WaitGroup
		wg.Add(10)
		for i := 0; i < 10; i++ {
			go func() {
				defer wg.Done()
				url := s.imageURL(c, "lxc", "trusty", "amd64")
				response, err := s.downloadRequest(c, url)
				c.Assert(err, jc.ErrorIsNil)
				data := s.testDownload(c, response)
				c.Assert(string(data), gc.Equals, string(s.imageData))
			}()
		}
		wg.Wait()
		done <- struct{}{}
	}()
	select {
	case <-done:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out waiting for images to be fetced")
	}

	// Downloading an image is 2 requests - one for image, one for SA256.
	c.Assert(testRoundTripper.Sub.(*CountingRoundTripper).count, gc.Equals, 2)

	// Check that the image is correctly cached.
	metadata, cachedData := s.getImageFromStorage(c, s.State, "lxc", "trusty", "amd64")
	c.Assert(metadata.Size, gc.Equals, int64(len(s.imageData)))
	c.Assert(metadata.SHA256, gc.Equals, s.imageChecksum)
	c.Assert(metadata.SourceURL, gc.Equals, "test://cloud-images/trusty-released-amd64-root.tar.gz")
	c.Assert(s.imageData, gc.Equals, string(cachedData))
}
开发者ID:Pankov404,项目名称:juju,代码行数:46,代码来源:images_test.go


示例18: TestListBlockDevicesBlockDeviceInUseError

func (s *ListBlockDevicesSuite) TestListBlockDevicesBlockDeviceInUseError(c *gc.C) {
	s.PatchValue(diskmanager.BlockDeviceInUse, func(dev storage.BlockDevice) (bool, error) {
		return false, errors.New("badness")
	})
	testing.PatchExecutable(c, s, "lsblk", `#!/bin/bash --norc
cat <<EOF
KNAME="sda" SIZE="240057409536" LABEL="" UUID="" TYPE="disk"
EOF`)

	// If the in-use check errors, the block device will be marked "in use"
	// to prevent it from being used, but no error will be returned.
	devices, err := diskmanager.ListBlockDevices()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(devices, jc.SameContents, []storage.BlockDevice{{
		DeviceName: "sda",
		Size:       228936,
		InUse:      true,
	}})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:19,代码来源:lsblk_test.go


示例19: TestListBlockDevicesLsblkBadOutput

func (s *ListBlockDevicesSuite) TestListBlockDevicesLsblkBadOutput(c *gc.C) {
	// Extra key/value pairs should be ignored; invalid sizes should
	// be logged and ignored (Size will be set to zero).
	testing.PatchExecutable(c, s, "lsblk", `#!/bin/bash --norc
cat <<EOF
KNAME="sda" SIZE="eleventy" LABEL="" UUID="" TYPE="disk"
KNAME="sdb" SIZE="1048576" LABEL="" UUID="" BOB="DOBBS" TYPE="disk"
EOF`)

	devices, err := diskmanager.ListBlockDevices()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(devices, jc.SameContents, []storage.BlockDevice{{
		DeviceName: "sda",
		Size:       0,
	}, {
		DeviceName: "sdb",
		Size:       1,
	}})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:19,代码来源:lsblk_test.go


示例20: TestListBlockDevicesDeviceFiltering

func (s *ListBlockDevicesSuite) TestListBlockDevicesDeviceFiltering(c *gc.C) {
	testing.PatchExecutable(c, s, "lsblk", `#!/bin/bash --norc
cat <<EOF
KNAME="sda" SIZE="240057409536" LABEL="" UUID="" TYPE="disk"
KNAME="sda1" SIZE="254803968" LABEL="" UUID="" TYPE="part"
KNAME="loop0" SIZE="254803968" LABEL="" UUID="" TYPE="loop"
KNAME="sr0" SIZE="254803968" LABEL="" UUID="" TYPE="rom"
KNAME="whatever" SIZE="254803968" LABEL="" UUID="" TYPE="lvm"
EOF`)

	devices, err := diskmanager.ListBlockDevices()
	c.Assert(err, gc.IsNil)
	c.Assert(devices, jc.SameContents, []storage.BlockDevice{{
		DeviceName: "sda",
		Size:       228936,
	}, {
		DeviceName: "loop0",
		Size:       243,
	}})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:20,代码来源:lsblk_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang testing.PatchExecutableAsEchoArgs函数代码示例发布时间:2022-05-23
下一篇:
Golang testing.NewClock函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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