當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeCmdRunner.AddCmdResult方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeCmdRunner.AddCmdResult方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeCmdRunner.AddCmdResult方法的具體用法?Golang FakeCmdRunner.AddCmdResult怎麽用?Golang FakeCmdRunner.AddCmdResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/bosh-utils/system/fakes.FakeCmdRunner的用法示例。


在下文中一共展示了FakeCmdRunner.AddCmdResult方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

			Expect(2).To(Equal(len(fakeRunner.RunCommands)))
			Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))

		})

		Context("when mke2fs errors", func() {
			var fakeRunner *fakesys.FakeCmdRunner
			var fakeFs *fakesys.FakeFileSystem
			var mkeCmd string

			BeforeEach(func() {
				fakeRunner = fakesys.NewFakeCmdRunner()
				fakeFs = fakesys.NewFakeFileSystem()
				fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
				fakeRunner.AddCmdResult("blkid -p /dev/xvda2", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})

				mkeCmd = fmt.Sprintf("mke2fs -t %s -j -E lazy_itable_init=1 %s", FileSystemExt4, "/dev/xvda2")
			})

			It("retries mke2fs if the erros is 'device is already in use'", func() {
				fakeRunner.AddCmdResult(mkeCmd, fakesys.FakeCmdResult{
					Error: errors.New(`mke2fs 1.42.9 (4-Feb-2014)
/dev/xvdf1 is apparently in use by the system; will not make a filesystem here`),
				})
				fakeRunner.AddCmdResult(mkeCmd, fakesys.FakeCmdResult{
					ExitStatus: 0,
				})
				formatter := NewLinuxFormatter(fakeRunner, fakeFs)
				formatter.Format("/dev/xvda2", FileSystemExt4)
開發者ID:mattcui,項目名稱:bosh-agent,代碼行數:29,代碼來源:linux_formatter_test.go

示例2:

				Expect(ip).To(Equal("74.125.239.101"))
			})
		})

		Context("when host is not an ip", func() {
			It("returns 127.0.0.1 for 'localhost'", func() {
				ip, err := resolver.LookupHost([]string{"8.8.8.8"}, "localhost")
				Expect(err).ToNot(HaveOccurred())
				Expect(ip).To(Equal("127.0.0.1"))
			})

			It("returns ip for resolved host", func() {
				digResult := fakesys.FakeCmdResult{
					Stdout: "74.125.19.99",
				}
				runner.AddCmdResult("dig @8.8.8.8 google.com. +short +time=1", digResult)
				ip, err := resolver.LookupHost([]string{"8.8.8.8"}, "google.com.")
				Expect(err).ToNot(HaveOccurred())
				Expect(ip).To(Equal("74.125.19.99"))
			})

			It("returns ip for resolved host after failing and then succeeding", func() {
				digResult := fakesys.FakeCmdResult{
					Stdout: "74.125.19.99",
				}
				runner.AddCmdResult("dig @8.8.8.8 google.com. +short +time=1", digResult)
				ip, err := resolver.LookupHost([]string{"127.0.0.127", "8.8.8.8"}, "google.com.")
				Expect(err).ToNot(HaveOccurred())
				Expect(ip).To(Equal("74.125.19.99"))
			})
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:30,代碼來源:dig_dns_resolver_test.go

示例3:

		runner   *fakesys.FakeCmdRunner
		searcher RoutesSearcher
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		searcher = NewCmdRoutesSearcher(runner)
	})

	Describe("SearchRoutes", func() {
		Context("when running command succeeds", func() {
			It("returns parsed routes information", func() {
				runner.AddCmdResult("route -n", fakesys.FakeCmdResult{
					Stdout: `Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.79.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         172.16.79.1     0.0.0.0         UG    0      0        0 eth0
`,
				})

				routes, err := searcher.SearchRoutes()
				Expect(err).ToNot(HaveOccurred())
				Expect(routes).To(Equal([]Route{
					Route{Destination: "172.16.79.0", Gateway: "0.0.0.0", InterfaceName: "eth0"},
					Route{Destination: "169.254.0.0", Gateway: "0.0.0.0", InterfaceName: "eth0"},
					Route{Destination: "0.0.0.0", Gateway: "172.16.79.1", InterfaceName: "eth0"},
				}))
			})

			It("ignores empty lines", func() {
				runner.AddCmdResult("route -n", fakesys.FakeCmdResult{
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:32,代碼來源:cmd_routes_searcher_test.go

示例4:

			})

			It("returns error", func() {
				_, _, err := compiler.Compile(pkg)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Packaging script for package 'fake-package-1' not found"))
			})
		})

		Context("when the packaging script fails", func() {
			JustBeforeEach(func() {
				fakeResult := fakesys.FakeCmdResult{
					ExitStatus: 1,
					Error:      errors.New("fake-error"),
				}
				runner.AddCmdResult("bash -x packaging", fakeResult)
			})

			It("returns error", func() {
				_, _, err := compiler.Compile(pkg)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Compiling package"))
				Expect(err.Error()).To(ContainSubstring("fake-error"))
			})
		})

		Context("when compression fails", func() {
			JustBeforeEach(func() {
				compressor.CompressFilesInDirErr = errors.New("fake-compression-error")
			})
開發者ID:mattcui,項目名稱:bosh-init,代碼行數:30,代碼來源:compiler_test.go

示例5:

			Expect(actualCmd.WorkingDir).To(Equal("/fake-working-dir"))
		})

		It("returns an error if it fails to save output", func() {
			fs.OpenFileErr = errors.New("fake-open-file-error")

			_, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-open-file-error"))
		})

		Context("when command succeeds", func() {
			BeforeEach(func() {
				cmdRunner.AddCmdResult("fake-cmd fake-args", fakesys.FakeCmdResult{
					Stdout:     "fake-stdout",
					Stderr:     "fake-stderr",
					ExitStatus: 0,
				})
			})

			It("returns correct result", func() {
				expectedResult := &CmdResult{
					IsStdoutTruncated: false,
					Stdout:            []byte("fake-stdout"),
					Stderr:            []byte("fake-stderr"),
					ExitStatus:        0,
				}

				result, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
				Expect(err).ToNot(HaveOccurred())
				Expect(result).To(Equal(expectedResult))
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:31,代碼來源:file_logging_cmd_runner_test.go

示例6:

	BeforeEach(func() {
		logger = boshlog.NewLogger(boshlog.LevelNone)
		fakeCmdRunner = fakesys.NewFakeCmdRunner()
		fakeclock = &fakeboshaction.FakeClock{}
		partitioner = NewPartedPartitioner(logger, fakeCmdRunner, fakeclock)
	})

	Describe("Partition", func() {
		Context("when the desired partitions do not exist", func() {
			Context("when there is no partition table", func() {
				BeforeEach(func() {
					fakeCmdRunner.AddCmdResult(
						"parted -m /dev/sda unit B print",
						fakesys.FakeCmdResult{
							Stdout:     "Error: /dev/sda: unrecognised disk label",
							ExitStatus: 1,
							Error:      errors.New("Error: /dev/sda: unrecognised disk label"),
						},
					)
					fakeCmdRunner.AddCmdResult(
						"parted -m /dev/sda unit B print",
						fakesys.FakeCmdResult{
							Stdout: `BYT;
/dev/xvdf:221190815744B:xvd:512:512:gpt:Xen Virtual Block Device;
`})
					fakeCmdRunner.AddCmdResult(
						"parted -s /dev/sda mklabel gpt",
						fakesys.FakeCmdResult{Stdout: "", ExitStatus: 0})
				})

				It("makes a gpt label and then creates partitions using parted", func() {
開發者ID:mattcui,項目名稱:bosh-agent,代碼行數:31,代碼來源:parted_partitioner_test.go

示例7:

			Expect(outBuf).To(MatchRegexp(expectedContent))
		})

		It("runs arp -d for the given IP", func() {
			expectedCommand := []string{"arp", "-d", address}
			cmd := cmdRunner.RunCommands[0]
			Expect(reflect.DeepEqual(cmd, expectedCommand)).To(BeTrue())
		})

		Context("When ARP deletion command returns an error", func() {
			BeforeEach(func() {
				cmd := fmt.Sprintf("arp -d %s", address)
				errorResult := fakesys.FakeCmdResult{
					Stdout:     "",
					Stderr:     "",
					ExitStatus: 1,
					Error:      errors.New("an error"),
					Sticky:     false,
				}
				cmdRunner.AddCmdResult(cmd, errorResult)
			})

			It("logs the error as INFO", func() {
				expectedContent := expectedLogFormat("INFO", fmt.Sprintf("Ignoring arp failure deleting %s from cache:.*", address))
				Expect(outBuf).To(MatchRegexp(expectedContent))
			})
		})
	})

})
開發者ID:teddyking,項目名稱:bosh-agent,代碼行數:30,代碼來源:arp_test.go

示例8: describeUbuntuNetManager


//.........這裏部分代碼省略.........
    address 2.2.2.2
    network 2.2.2.0
    netmask 255.255.255.0
    broadcast 2.2.2.255
    gateway 3.4.5.6
`

				Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfiguration))
			})

			It("configures network for a single physical device, when a virtual device is also present", func() {
				staticNetworkWithoutMAC := boshsettings.Network{
					Type:    "manual",
					IP:      "2.2.2.2",
					Default: []string{"gateway"},
					Netmask: "255.255.255.0",
					Gateway: "3.4.5.6",
				}

				stubInterfacesWithVirtual(
					map[string]boshsettings.Network{
						"ethstatic": staticNetwork,
					},
					[]string{"virtual"},
				)
				interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
					boship.NewSimpleInterfaceAddress("ethstatic", "2.2.2.2"),
				}

				err := netManager.SetupNetworking(boshsettings.Networks{
					"static-network": staticNetworkWithoutMAC,
				}, nil)
				Expect(err).ToNot(HaveOccurred())

				networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
				Expect(networkConfig).ToNot(BeNil())

				expectedNetworkConfiguration := `# Generated by bosh-agent
auto lo
iface lo inet loopback

auto ethstatic
iface ethstatic inet static
    address 2.2.2.2
    network 2.2.2.0
    netmask 255.255.255.0
    broadcast 2.2.2.255
    gateway 3.4.5.6
`

				Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfiguration))
			})
		})
	})

	Describe("GetConfiguredNetworkInterfaces", func() {
		Context("when there are network devices", func() {
			BeforeEach(func() {
				interfacePaths := []string{}
				interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth0", "aa:bb", true))
				interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth1", "cc:dd", true))
				interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth2", "ee:ff", true))
				fs.SetGlob("/sys/class/net/*", interfacePaths)
			})

			It("returns networks that are defined in /etc/network/interfaces", func() {
				cmdRunner.AddCmdResult("ifup --no-act fake-eth0", fakesys.FakeCmdResult{
					Stdout:     "",
					Stderr:     "ifup: interface fake-eth0 already configured",
					ExitStatus: 0,
				})

				cmdRunner.AddCmdResult("ifup --no-act fake-eth1", fakesys.FakeCmdResult{
					Stdout:     "",
					Stderr:     "Ignoring unknown interface fake-eth1=fake-eth1.",
					ExitStatus: 0,
				})

				cmdRunner.AddCmdResult("ifup --no-act fake-eth2", fakesys.FakeCmdResult{
					Stdout:     "",
					Stderr:     "ifup: interface fake-eth2 already configured",
					ExitStatus: 0,
				})

				interfaces, err := netManager.GetConfiguredNetworkInterfaces()
				Expect(err).ToNot(HaveOccurred())

				Expect(interfaces).To(ConsistOf("fake-eth0", "fake-eth2"))
			})
		})

		Context("when there are no network devices", func() {
			It("returns empty list", func() {
				interfaces, err := netManager.GetConfiguredNetworkInterfaces()
				Expect(err).ToNot(HaveOccurred())
				Expect(interfaces).To(Equal([]string{}))
			})
		})
	})
}
開發者ID:ardnaxelarak,項目名稱:bosh-agent,代碼行數:101,代碼來源:ubuntu_net_manager_test.go

示例9:

	var (
		runner   *fakesys.FakeCmdRunner
		searcher MountsSearcher
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		searcher = NewCmdMountsSearcher(runner)
	})

	Describe("SearchMounts", func() {
		Context("when running command succeeds", func() {
			It("returns parsed mount information", func() {
				runner.AddCmdResult("mount", fakesys.FakeCmdResult{
					Stdout: `devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
/dev/sda1 on /boot type ext2 (rw)
none on /tmp/warden/cgroup type tmpfs (rw)`,
				})

				mounts, err := searcher.SearchMounts()
				Expect(err).ToNot(HaveOccurred())
				Expect(mounts).To(Equal([]Mount{
					Mount{PartitionPath: "devpts", MountPoint: "/dev/pts"},
					Mount{PartitionPath: "tmpfs", MountPoint: "/run"},
					Mount{PartitionPath: "/dev/sda1", MountPoint: "/boot"},
					Mount{PartitionPath: "none", MountPoint: "/tmp/warden/cgroup"},
				}))
			})

			It("ignores empty lines", func() {
				runner.AddCmdResult("mount", fakesys.FakeCmdResult{
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:32,代碼來源:cmd_mounts_searcher_test.go

示例10:

var _ = Describe("MonitRetryable", func() {
	var (
		cmdRunner      *fakesys.FakeCmdRunner
		monitRetryable boshretry.Retryable
	)

	BeforeEach(func() {
		cmdRunner = fakesys.NewFakeCmdRunner()
		monitRetryable = NewMonitRetryable(cmdRunner)
	})

	Describe("Attempt", func() {
		Context("when starting monit fails", func() {
			BeforeEach(func() {
				cmdRunner.AddCmdResult("sv start monit", fakesys.FakeCmdResult{
					ExitStatus: 255,
					Error:      errors.New("fake-start-monit-error"),
				})
			})

			It("is retryable and returns err", func() {
				isRetryable, err := monitRetryable.Attempt()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-start-monit-error"))
				Expect(isRetryable).To(BeTrue())
				Expect(len(cmdRunner.RunCommands)).To(Equal(1))
				Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"sv", "start", "monit"}))
			})
		})

		Context("when starting succeeds", func() {
			BeforeEach(func() {
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:32,代碼來源:monit_retryable_test.go

示例11:

			Expect(runner.RunCommands).To(
				ContainElement([]string{"-Command", fmt.Sprintf(NicSettingsTemplate, network1.Mac, network1.IP, network1.Netmask, network1.Gateway)}))
			Expect(runner.RunCommands).To(
				ContainElement([]string{"-Command", fmt.Sprintf(NicSettingsTemplate, network2.Mac, network2.IP, network2.Netmask, "")}))
		})

		It("ignores VIP networks", func() {
			err := setupNetworking(boshsettings.Networks{"vip": vip})
			Expect(err).ToNot(HaveOccurred())
			Expect(runner.RunCommands).To(ContainElement([]string{"-Command", ResetDNSTemplate}))
		})

		It("returns an error when configuring fails", func() {
			setupMACs(network1)
			runner.AddCmdResult(
				"-Command "+fmt.Sprintf(NicSettingsTemplate, network1.Mac, network1.IP, network1.Netmask, network1.Gateway),
				fakesys.FakeCmdResult{Error: errors.New("fake-err")},
			)

			err := setupNetworking(boshsettings.Networks{"static-1": network1})
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(Equal("Configuring interface: fake-err"))
		})
	})

	Context("when there is a network marked default for DNS", func() {
		It("configures DNS with a single DNS server", func() {
			network := boshsettings.Network{
				Type:    "manual",
				DNS:     []string{"8.8.8.8"},
				Default: []string{"gateway", "dns"},
			}
開發者ID:jianqiu,項目名稱:bosh-agent,代碼行數:32,代碼來源:windows_net_manager_test.go

示例12:

var _ = Describe("sfdiskPartitioner", func() {
	var (
		runner      *fakesys.FakeCmdRunner
		partitioner Partitioner
	)

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		logger := boshlog.NewLogger(boshlog.LevelNone)

		partitioner = NewSfdiskPartitioner(logger, runner)
	})

	It("sfdisk partition", func() {
		runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump})

		partitions := []Partition{
			{Type: PartitionTypeSwap, SizeInBytes: 512 * 1024 * 1024},
			{Type: PartitionTypeLinux, SizeInBytes: 1024 * 1024 * 1024},
			{Type: PartitionTypeLinux, SizeInBytes: 512 * 1024 * 1024},
		}

		partitioner.Partition("/dev/sda", partitions)

		Expect(1).To(Equal(len(runner.RunCommandsWithInput)))
		Expect(runner.RunCommandsWithInput[0]).To(Equal([]string{",512,S\n,1024,L\n,,L\n", "sfdisk", "-uM", "/dev/sda"}))
	})

	It("sfdisk partition with no partition table", func() {
		runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stderr: devSdaSfdiskNotableDumpStderr})
開發者ID:nimbus-cloud,項目名稱:bosh-agent,代碼行數:30,代碼來源:sfdisk_partitioner_test.go

示例13:

			})
		})
	})

	Describe("StartJobSupervisor", func() {
		It("should start monit service", func() {

			err := monit.StartJobSupervisor()
			Expect(err).ToNot(HaveOccurred())

			Expect(len(runner.RunCommands)).To(Equal(1))
			Expect(runner.RunCommands[0]).To(Equal([]string{"sv", "start", "monit"}))
		})

		It("should return error when starting monit service fails", func() {
			runner.AddCmdResult("sv start monit", fakesys.FakeCmdResult{Error: errors.New("fake-monit-error")})
			err := monit.StartJobSupervisor()
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-monit-error"))

			Expect(len(runner.RunCommands)).To(Equal(1))
			Expect(runner.RunCommands[0]).To(Equal([]string{"sv", "start", "monit"}))
		})
	})

	Describe("StopJobSupervisor", func() {
		It("should stop monit service", func() {

			err := monit.StopJobSupervisor()
			Expect(err).ToNot(HaveOccurred())
開發者ID:vinodpanicker,項目名稱:bosh-agent,代碼行數:30,代碼來源:monit_job_supervisor_test.go

示例14:

		fs = fakesys.NewFakeFileSystem()
		cmdRunner = fakesys.NewFakeCmdRunner()
		directorInfo := bltaction.DirectorInfo{
			UUID: "fake-director-uuid",
			URL:  "fake-director-url",
		}
		boshCmd := boshsys.Command{Name: "bosh"}

		fs.ReturnTempFile = fakesys.NewFakeFile("cli-config-path", fs)

		cliRunner := bltclirunner.NewRunner(boshCmd, cmdRunner, fs)
		cliRunner.Configure()
		renderer := NewRenderer(fs)

		cmdRunner.AddCmdResult("bosh -n -c cli-config-path deploy", fakesys.FakeCmdResult{
			Stdout: "Task 15 done",
		})

		cmdRunner.AddCmdResult("bosh -n -c cli-config-path deploy", fakesys.FakeCmdResult{
			Stdout: "Task 20 done",
		})

		parameters := bftconfig.Parameters{
			NameLength:                 []int{5, 10},
			Instances:                  []int{2, 4},
			AvailabilityZones:          [][]string{[]string{"z1"}, []string{"z1", "z2"}},
			PersistentDiskDefinition:   []string{"disk_type", "disk_pool"},
			PersistentDiskSize:         []int{0, 100},
			NumberOfJobs:               []int{1, 2},
			MigratedFromCount:          []int{0},
			VmTypeDefinition:           []string{"vm_type"},
開發者ID:cloudfoundry-incubator,項目名稱:bosh-fuzz-tests,代碼行數:31,代碼來源:deployer_test.go

示例15:

			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-temp-dir-error"))
		})
	})

	Context("when writing renderer script fails", func() {
		It("returns an error", func() {
			fs.WriteFileError = errors.New("fake-write-error")
			err := erbRenderer.Render("src-path", "dst-path", context)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-write-error"))
		})
	})

	Context("when running ruby command fails", func() {
		BeforeEach(func() {
			runner.AddCmdResult(
				"ruby fake-temp-dir/erb-render.rb fake-temp-dir/erb-context.json fake-src-path fake-dst-path",
				fakesys.FakeCmdResult{
					Error: errors.New("fake-cmd-error"),
				})
		})

		It("returns an error", func() {
			err := erbRenderer.Render("fake-src-path", "fake-dst-path", context)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-cmd-error"))
		})
	})
})
開發者ID:mattcui,項目名稱:bosh-init,代碼行數:30,代碼來源:erb_renderer_test.go


注:本文中的github.com/cloudfoundry/bosh-utils/system/fakes.FakeCmdRunner.AddCmdResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。