当前位置: 首页>>代码示例>>Golang>>正文


Golang Container.StreamOut方法代码示例

本文整理汇总了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() {
开发者ID:guanglinlv,项目名称:garden,代码行数:31,代码来源:container_test.go

示例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"),
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:31,代码来源:container_test.go

示例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() {
开发者ID:digideskio,项目名称:guardian,代码行数:30,代码来源:gardener_test.go

示例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)
			})
开发者ID:vito,项目名称:gaol,代码行数:31,代码来源:container_test.go

示例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() {
开发者ID:julz,项目名称:garden-runc,代码行数:31,代码来源:request_handling_test.go

示例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,
			})
开发者ID:pcfdev-forks,项目名称:houdini,代码行数:31,代码来源:container_test.go

示例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("")
开发者ID:digideskio,项目名称:guardian,代码行数:31,代码来源:streaming_test.go


注:本文中的github.com/cloudfoundry-incubator/garden.Container.StreamOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。