本文整理匯總了Golang中code/cloudfoundry/org/garden.Container.Attach方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.Attach方法的具體用法?Golang Container.Attach怎麽用?Golang Container.Attach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/garden.Container
的用法示例。
在下文中一共展示了Container.Attach方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Stdout: io.MultiWriter(GinkgoWriter, out),
Stderr: io.MultiWriter(GinkgoWriter, out),
})
Expect(err).NotTo(HaveOccurred())
exitCode, err := proc.Wait()
Expect(err).NotTo(HaveOccurred())
Expect(exitCode).To(Equal(12))
Expect(out).To(gbytes.Say("hello"))
})
It("can reattach to processes that are still running", func() {
out := gbytes.NewBuffer()
procId := existingProc.ID()
process, err := container.Attach(procId, garden.ProcessIO{
Stdout: io.MultiWriter(GinkgoWriter, out),
Stderr: io.MultiWriter(GinkgoWriter, out),
})
Expect(err).NotTo(HaveOccurred())
Eventually(out).Should(gbytes.Say("hello"))
Expect(process.Signal(garden.SignalKill)).To(Succeed())
exited := make(chan struct{})
go func() {
process.Wait()
close(exited)
}()
Eventually(exited).Should(BeClosed())
})
示例2:
container, err = client.Create(garden.ContainerSpec{})
Expect(err).NotTo(HaveOccurred())
process, err := container.Run(garden.ProcessSpec{
Path: "sh",
Args: []string{"-c", "sleep 10; exit 13"},
}, garden.ProcessIO{})
Expect(err).NotTo(HaveOccurred())
processID = process.ID()
restartGarden(client, args...)
})
It("returns the exit code", func() {
attachedProcess, err := container.Attach(processID, garden.ProcessIO{})
Expect(err).NotTo(HaveOccurred())
exitCode, err := attachedProcess.Wait()
Expect(err).NotTo(HaveOccurred())
Expect(exitCode).To(Equal(13))
})
})
Context("when the process exits before calling .Attach", func() {
BeforeEach(func() {
var err error
container, err = client.Create(garden.ContainerSpec{})
Expect(err).NotTo(HaveOccurred())
process, err := container.Run(garden.ProcessSpec{
示例3:
_, err = fmt.Fprintf(io.Stderr, "stderr data")
Ω(err).ShouldNot(HaveOccurred())
}()
return process, nil
}
stdout := gbytes.NewBuffer()
stderr := gbytes.NewBuffer()
processIO := garden.ProcessIO{
Stdout: stdout,
Stderr: stderr,
}
process, err := container.Attach("process-handle", processIO)
Ω(err).ShouldNot(HaveOccurred())
attachedHandle, attachedID, attachedIO := fakeConnection.AttachArgsForCall(0)
Ω(attachedHandle).Should(Equal("some-handle"))
Ω(attachedID).Should(Equal("process-handle"))
Ω(attachedIO).Should(Equal(processIO))
Ω(process.ID()).Should(Equal("process-handle"))
status, err := process.Wait()
Ω(err).ShouldNot(HaveOccurred())
Ω(status).Should(Equal(123))
Eventually(stdout).Should(gbytes.Say("stdout data"))
Eventually(stderr).Should(gbytes.Say("stderr data"))