本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden/warden.Container.StreamIn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.StreamIn方法的具體用法?Golang Container.StreamIn怎麽用?Golang Container.StreamIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/garden/warden.Container
的用法示例。
在下文中一共展示了Container.StreamIn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
{
Name: "./some-temp-dir/some-temp-file",
Body: "some-body",
},
},
)
tgz, err := os.Open(tgzPath)
Ω(err).ShouldNot(HaveOccurred())
tarStream, err = gzip.NewReader(tgz)
Ω(err).ShouldNot(HaveOccurred())
})
It("creates the files in the container", func() {
tarInput, err := container.StreamIn("/tmp/some-container-dir")
Ω(err).ShouldNot(HaveOccurred())
_, err = io.Copy(tarInput, tarStream)
Ω(err).ShouldNot(HaveOccurred())
tarInput.Close()
_, stream, err := container.Run(warden.ProcessSpec{
Script: `test -f /tmp/some-container-dir/some-temp-dir/some-temp-file && exit 42`,
})
Expect(*(<-stream).ExitStatus).To(Equal(uint32(42)))
})
Context("and then copying them out", func() {
示例2:
It("returns the error", func() {
_, err := container.Info()
Ω(err).Should(Equal(disaster))
})
})
})
Describe("StreamIn", func() {
It("sends a stream in request", func() {
reader, w := io.Pipe()
fakeConnection.WhenStreamingIn = func(handle string, dst string) (io.WriteCloser, error) {
Ω(dst).Should(Equal("to"))
return w, nil
}
writer, err := container.StreamIn("to")
Ω(err).ShouldNot(HaveOccurred())
go func() {
writer.Write([]byte("stuff"))
writer.Close()
}()
content, err := ioutil.ReadAll(reader)
Ω(err).ShouldNot(HaveOccurred())
Ω(string(content)).Should(Equal("stuff"))
})
Context("when streaming in fails", func() {
disaster := errors.New("oh no!")