本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Container.StreamOut方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.StreamOut方法的具体用法?Golang Container.StreamOut怎么用?Golang Container.StreamOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/garden.Container
的用法示例。
在下文中一共展示了Container.StreamOut方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
It("returns the error", func() {
err := container.StreamIn(garden.StreamInSpec{
Path: "to",
})
Ω(err).Should(Equal(disaster))
})
})
})
Describe("StreamOut", func() {
It("sends a stream out request", func() {
fakeConnection.StreamOutReturns(ioutil.NopCloser(strings.NewReader("kewl")), nil)
reader, err := container.StreamOut(garden.StreamOutSpec{
User: "deandra",
Path: "from",
})
bytes, err := ioutil.ReadAll(reader)
Ω(err).ShouldNot(HaveOccurred())
Ω(string(bytes)).Should(Equal("kewl"))
handle, spec := fakeConnection.StreamOutArgsForCall(0)
Ω(handle).Should(Equal("some-handle"))
Ω(spec.Path).Should(Equal("from"))
Ω(spec.User).Should(Equal("deandra"))
})
Context("when streaming out fails", func() {
disaster := errors.New("oh no!")
BeforeEach(func() {
示例2:
})
})
Describe("StreamOut", func() {
Context("Containerizer returns 200", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/containers/containerhandle/files", "source=a/path"),
ghttp.RespondWith(200, "a tarball"),
),
)
})
It("makes a call out to an external service", func() {
stream, err := container.StreamOut(garden.StreamOutSpec{Path: "a/path"})
Expect(err).NotTo(HaveOccurred())
defer stream.Close()
Expect(server.ReceivedRequests()).Should(HaveLen(1))
body, err := ioutil.ReadAll(stream)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).Should(Equal("a tarball"))
})
})
Context("Containerizer returns non 200", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/containers/containerhandle/files", "source=a/path"),
示例3:
Describe("streaming files in to the container", func() {
It("asks the containerizer to stream in the tar stream", func() {
spec := garden.StreamInSpec{Path: "potato", User: "chef", TarStream: gbytes.NewBuffer()}
Expect(container.StreamIn(spec)).To(Succeed())
_, handle, specArg := containerizer.StreamInArgsForCall(0)
Expect(handle).To(Equal("banana"))
Expect(specArg).To(Equal(spec))
})
})
Describe("streaming files outside the container", func() {
It("asks the containerizer to stream out the files", func() {
spec := garden.StreamOutSpec{Path: "potato", User: "chef"}
_, err := container.StreamOut(spec)
Expect(err).To(Succeed())
_, handle, specArg := containerizer.StreamOutArgsForCall(0)
Expect(handle).To(Equal("banana"))
Expect(specArg).To(Equal(spec))
})
})
})
Describe("listing containers", func() {
BeforeEach(func() {
containerizer.HandlesReturns([]string{"banana", "banana2", "cola"}, nil)
})
It("should return matching containers", func() {
示例4:
fakeConnection.StreamInReturns(
disaster)
})
It("returns the error", func() {
err := container.StreamIn("to", nil)
Ω(err).Should(Equal(disaster))
})
})
})
Describe("StreamOut", func() {
It("sends a stream out request", func() {
fakeConnection.StreamOutReturns(ioutil.NopCloser(strings.NewReader("kewl")), nil)
reader, err := container.StreamOut("from")
bytes, err := ioutil.ReadAll(reader)
Ω(err).ShouldNot(HaveOccurred())
Ω(string(bytes)).Should(Equal("kewl"))
handle, src := fakeConnection.StreamOutArgsForCall(0)
Ω(handle).Should(Equal("some-handle"))
Ω(src).Should(Equal("from"))
})
Context("when streaming out fails", func() {
disaster := errors.New("oh no!")
BeforeEach(func() {
fakeConnection.StreamOutReturns(nil, disaster)
})
示例5:
})
})
Describe("streaming out", func() {
var streamOut io.ReadCloser
BeforeEach(func() {
streamOut = ioutil.NopCloser(bytes.NewBuffer([]byte("hello-world!")))
})
JustBeforeEach(func() {
fakeContainer.StreamOutReturns(streamOut, nil)
})
It("streams the bits out and succeeds", func() {
reader, err := container.StreamOut("/src/path")
Ω(err).ShouldNot(HaveOccurred())
Ω(reader).ShouldNot(BeZero())
streamedContent, err := ioutil.ReadAll(reader)
Ω(err).ShouldNot(HaveOccurred())
Ω(string(streamedContent)).Should(Equal("hello-world!"))
Ω(fakeContainer.StreamOutArgsForCall(0)).Should(Equal("/src/path"))
})
Context("when the connection dies as we're streaming", func() {
var closer *closeChecker
BeforeEach(func() {
示例6:
touch a
touch b
mkdir foo/
touch foo/in-foo-a
touch foo/in-foo-b
`,
},
}, garden.ProcessIO{
Stdout: GinkgoWriter,
Stderr: GinkgoWriter,
})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0))
out, err := container.StreamOut(garden.StreamOutSpec{
Path: ".",
})
Expect(err).ToNot(HaveOccurred())
outBytes, err := ioutil.ReadAll(out)
data := ioutil.NopCloser(bytes.NewReader(outBytes))
Expect(backend.Destroy(container.Handle())).To(Succeed())
destinationContainer, err = backend.Create(garden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
err = destinationContainer.StreamIn(garden.StreamInSpec{
Path: ".",
TarStream: data,
})
示例7:
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)
Expect(err).NotTo(HaveOccurred())
statusCode, err := process.Wait()
Expect(err).NotTo(HaveOccurred())
Expect(statusCode).To(Equal(0))
})
It("should stream out the files", func() {
tarStream, err := container.StreamOut(garden.StreamOutSpec{
Path: "/root/documents/some/reports",
User: "root",
})
Expect(err).NotTo(HaveOccurred())
tarReader := tar.NewReader(tarStream)
header, err := tarReader.Next()
Expect(err).ToNot(HaveOccurred())
Expect(header.Name).To(Equal("reports/"))
header, err = tarReader.Next()
Expect(err).ToNot(HaveOccurred())
Expect(header.Name).To(Equal("reports/test"))
buffer := bytes.NewBufferString("")