本文整理匯總了Golang中code/cloudfoundry/org/garden.Container.StreamIn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.StreamIn方法的具體用法?Golang Container.StreamIn怎麽用?Golang Container.StreamIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/garden.Container
的用法示例。
在下文中一共展示了Container.StreamIn方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: streamin
func streamin(ctr garden.Container, archive string) {
for i := 0; i < 20; i++ {
By(fmt.Sprintf("preparing stream %d for handle %s", i, ctr.Handle()))
// Stream in a tar file to ctr
var tarStream io.Reader
pwd, err := os.Getwd()
Expect(err).ToNot(HaveOccurred())
tgzPath := path.Join(pwd, archive)
tgz, err := os.Open(tgzPath)
Expect(err).ToNot(HaveOccurred())
tarStream, err = gzip.NewReader(tgz)
Expect(err).ToNot(HaveOccurred())
By(fmt.Sprintf("starting stream %d for handle: %s", i, ctr.Handle()))
Expect(ctr.StreamIn(garden.StreamInSpec{
User: "root",
Path: fmt.Sprintf("/root/stream-file-%d", i),
TarStream: tarStream,
})).To(Succeed())
By(fmt.Sprintf("stream %d done for handle: %s", i, ctr.Handle()))
tgz.Close()
}
}
示例2:
Describe("StreamIn", func() {
It("sends a stream in request", func() {
fakeConnection.StreamInStub = func(handle string, spec garden.StreamInSpec) error {
Ω(spec.Path).Should(Equal("to"))
Ω(spec.User).Should(Equal("frank"))
content, err := ioutil.ReadAll(spec.TarStream)
Ω(err).ShouldNot(HaveOccurred())
Ω(string(content)).Should(Equal("stuff"))
return nil
}
err := container.StreamIn(garden.StreamInSpec{
User: "frank",
Path: "to",
TarStream: bytes.NewBufferString("stuff"),
})
Ω(err).ShouldNot(HaveOccurred())
})
Context("when streaming in fails", func() {
disaster := errors.New("oh no!")
BeforeEach(func() {
fakeConnection.StreamInReturns(
disaster)
})
It("returns the error", func() {
err := container.StreamIn(garden.StreamInSpec{
示例3:
Body: "some-body",
},
},
)
tgz, err := os.Open(tgzPath)
Expect(err).ToNot(HaveOccurred())
tarStream, err = gzip.NewReader(tgz)
Expect(err).ToNot(HaveOccurred())
})
It("should stream in the files", func() {
Expect(container.StreamIn(garden.StreamInSpec{
Path: "/root/test",
User: "root",
TarStream: tarStream,
})).To(Succeed())
Expect(container).To(HaveFile("/root/test/some-temp-dir"))
Expect(container).To(HaveFile("/root/test/some-temp-dir/some-temp-file"))
})
})
Describe("StreamOut", func() {
BeforeEach(func() {
process, err := container.Run(garden.ProcessSpec{
User: "root",
Path: "sh",
Args: []string{"-c", "mkdir -p /root/documents/some/reports && echo hello > /root/documents/some/reports/test"},
}, ginkgoIO)