本文整理汇总了Golang中github.com/cloudfoundry/gunk/command_runner/fake_command_runner.FakeCommandRunner.ExecutedCommands方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeCommandRunner.ExecutedCommands方法的具体用法?Golang FakeCommandRunner.ExecutedCommands怎么用?Golang FakeCommandRunner.ExecutedCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/gunk/command_runner/fake_command_runner.FakeCommandRunner
的用法示例。
在下文中一共展示了FakeCommandRunner.ExecutedCommands方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
})
It("executes the nstar command with the right arguments", func() {
Expect(fakeCommandRunner).To(HaveExecutedSerially(fake_command_runner.CommandSpec{
Path: "path-to-nstar",
Args: []string{
"path-to-tar",
"12",
"some-user",
"some-path",
},
}))
})
It("attaches the tarStream reader to stdin", func() {
Expect(fakeCommandRunner.ExecutedCommands()[0].Stdin).To(Equal(someStream))
})
})
Context("when it fails", func() {
It("returns the contents of stdout and error on failure", func() {
fakeCommandRunner.WhenRunning(fake_command_runner.CommandSpec{}, func(cmd *exec.Cmd) error {
cmd.Stderr.Write([]byte("some error output"))
cmd.Stdout.Write([]byte("some std output"))
return errors.New("someerror")
})
Expect(nstar.StreamIn(lagertest.NewTestLogger("test"), 12, "some-path", "some-user", someStream)).To(
MatchError(ContainSubstring("some error output")),
)
示例2:
JustBeforeEach(func() {
commandRunner.WhenRunning(fake_command_runner.CommandSpec{
Path: "funC",
}, func(cmd *exec.Cmd) error {
logFile, err := os.Create(cmd.Args[3])
Expect(err).NotTo(HaveOccurred())
_, err = io.Copy(logFile, bytes.NewReader([]byte(logs)))
Expect(err).NotTo(HaveOccurred())
return runcExitStatus
})
})
It("creates the container with runC create", func() {
Expect(runner.Create(logger, bundlePath, "some-id", garden.ProcessIO{})).To(Succeed())
Expect(commandRunner.ExecutedCommands()[0].Path).To(Equal("funC"))
Expect(commandRunner.ExecutedCommands()[0].Args).To(ConsistOf(
"funC", "--debug", "--log", logFilePath, "create", "--no-new-keyring", "--bundle", bundlePath, "--pid-file", pidFilePath, "some-id",
))
})
Context("when running runc fails", func() {
BeforeEach(func() {
runcExitStatus = errors.New("some-error")
})
It("returns runc's exit status", func() {
Expect(runner.Create(logger, bundlePath, "some-id", garden.ProcessIO{})).To(MatchError("runc create: some-error: "))
})
})
示例3:
})
Describe("Create", func() {
BeforeEach(func() {
fakeCmdRunnerStdout = "/this-is/your\n"
})
It("uses the correct external-image-manager binary", func() {
_, _, err := externalImageManager.Create(
logger, "hello", rootfs_provider.Spec{
RootFS: baseImage,
},
)
Expect(err).ToNot(HaveOccurred())
Expect(len(fakeCommandRunner.ExecutedCommands())).To(Equal(1))
imageManagerCmd := fakeCommandRunner.ExecutedCommands()[0]
Expect(imageManagerCmd.Path).To(Equal("/external-image-manager-bin"))
})
It("returns the env variables defined in the image configuration", func() {
imagePath, err := ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())
fakeCmdRunnerStdout = imagePath
imageConfig := imageplugin.Image{
Config: imageplugin.ImageConfig{
Env: []string{"HELLO=there", "PATH=/my-path/bin"},
},
}
示例4:
Context("when a multiple destination networks are specified", func() {
It("opens only that IP", func() {
Expect(subject.PrependFilterRule(garden.NetOutRule{
Networks: []garden.IPRange{
{
Start: net.ParseIP("1.2.3.4"),
},
{
Start: net.ParseIP("2.2.3.4"),
End: net.ParseIP("2.2.3.9"),
},
},
})).To(Succeed())
Expect(fakeRunner.ExecutedCommands()).To(HaveLen(2))
Expect(fakeRunner).To(HaveExecutedSerially(
fake_command_runner.CommandSpec{
Path: "/sbin/iptables",
Args: []string{"-w", "-I", "foo-bar-baz", "1", "--protocol", "all", "--destination", "1.2.3.4", "--jump", "RETURN"},
},
fake_command_runner.CommandSpec{
Path: "/sbin/iptables",
Args: []string{"-w", "-I", "foo-bar-baz", "1", "--protocol", "all", "-m", "iprange", "--dst-range", "2.2.3.4-2.2.3.9", "--jump", "RETURN"},
},
))
})
})
Context("when a EndIP is specified without a StartIP", func() {
It("opens only that IP", func() {