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


Golang Container.StreamIn方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Container.StreamIn方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.StreamIn方法的具体用法?Golang Container.StreamIn怎么用?Golang Container.StreamIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/garden.Container的用法示例。


在下文中一共展示了Container.StreamIn方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ensureBuildDirExists

func (step *taskStep) ensureBuildDirExists(container garden.Container) error {
	emptyTar := new(bytes.Buffer)

	err := tar.NewWriter(emptyTar).Close()
	if err != nil {
		return err
	}

	err = container.StreamIn(garden.StreamInSpec{
		Path:      step.artifactsRoot,
		TarStream: emptyTar,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:savaki,项目名称:atc,代码行数:18,代码来源:task_step.go

示例2: createContainerDir

func createContainerDir(container garden.Container, dir string) error {
	emptyTar := new(bytes.Buffer)

	err := tar.NewWriter(emptyTar).Close()
	if err != nil {
		return err
	}

	err = container.StreamIn(garden.StreamInSpec{
		Path:      dir,
		TarStream: emptyTar,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:xoebus,项目名称:checkin,代码行数:18,代码来源:task_step.go

示例3: StreamIn

func StreamIn(c garden.Container) error {
	tarFile, err := os.Open("../../greenhouse-security-fixtures/output/SecurityFixtures.tgz")
	Expect(err).ShouldNot(HaveOccurred())
	defer tarFile.Close()
	return c.StreamIn(garden.StreamInSpec{Path: "bin", TarStream: tarFile})
}
开发者ID:khassib,项目名称:garden-windows,代码行数:6,代码来源:breakout_test.go

示例4:

			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PUT", "/api/containers/containerhandle/files", "destination=a/path"),
						func(w http.ResponseWriter, req *http.Request) {
							body, err := ioutil.ReadAll(req.Body)
							req.Body.Close()
							Expect(err).ShouldNot(HaveOccurred())
							Expect(string(body)).Should(Equal("stuff"))
						},
					),
				)
			})

			It("makes a call out to an external service", func() {
				err := container.StreamIn(garden.StreamInSpec{Path: "a/path", TarStream: strings.NewReader("stuff")})
				Expect(err).NotTo(HaveOccurred())
				Expect(server.ReceivedRequests()).Should(HaveLen(1))
			})
		})
		Context("Http PUT failure request", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("PUT", "/api/containers/containerhandle/files", "destination=a/path"),
						ghttp.RespondWith(500, ``),
						func(w http.ResponseWriter, req *http.Request) {
							req.Body.Close()
						},
					),
				)
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:31,代码来源:container_test.go

示例5:

		c, err = client.Create(garden.ContainerSpec{})
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		err := client.Destroy(c.Handle())
		Expect(err).ShouldNot(HaveOccurred())
	})

	Describe("process", func() {
		It("pid is returned", func() {
			tarFile, err := os.Open("../bin/consume.tar")
			Expect(err).ShouldNot(HaveOccurred())
			defer tarFile.Close()

			err = c.StreamIn(garden.StreamInSpec{Path: "bin", TarStream: tarFile})
			Expect(err).ShouldNot(HaveOccurred())

			buf := make([]byte, 0, 1024*1024)
			stdout := bytes.NewBuffer(buf)

			process, err := c.Run(garden.ProcessSpec{
				Path: "bin/consume.exe",
				Args: []string{"64"},
			}, garden.ProcessIO{Stdout: stdout})
			Expect(err).ShouldNot(HaveOccurred())
			Expect(process.ID()).ToNot(Equal("0"))
		})

		It("can be signaled", func(done Done) {
			for _, f := range []string{"../bin/loop.tar", "../bin/launcher.tar"} {
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:31,代码来源:lifecycle_test.go

示例6:

	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{
开发者ID:guanglinlv,项目名称:garden,代码行数:31,代码来源:container_test.go

示例7:

			Context("when the containerizer fails to run a process", func() {
				BeforeEach(func() {
					containerizer.RunReturns(nil, errors.New("lost my banana"))
				})

				It("returns the error", func() {
					_, err := container.Run(garden.ProcessSpec{}, garden.ProcessIO{})
					Expect(err).To(MatchError("lost my banana"))
				})
			})
		})

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

示例8:

		})
	})

	Describe("StreamIn", func() {
		It("sends a stream in request", func() {
			fakeConnection.StreamInStub = func(handle string, dst string, reader io.Reader) error {
				Ω(dst).Should(Equal("to"))

				content, err := ioutil.ReadAll(reader)
				Ω(err).ShouldNot(HaveOccurred())
				Ω(string(content)).Should(Equal("stuff"))

				return nil
			}

			err := container.StreamIn("to", 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("to", nil)
				Ω(err).Should(Equal(disaster))
			})
开发者ID:vito,项目名称:gaol,代码行数:31,代码来源:container_test.go

示例9:

					})
				})
			})
		})

		Describe("streaming in", func() {
			It("streams the file in, waits for completion, and succeeds", func() {
				data := bytes.NewBufferString("chunk-1;chunk-2;chunk-3;")

				fakeContainer.StreamInStub = func(dest string, stream io.Reader) error {
					Ω(dest).Should(Equal("/dst/path"))
					Ω(ioutil.ReadAll(stream)).Should(Equal([]byte("chunk-1;chunk-2;chunk-3;")))
					return nil
				}

				err := container.StreamIn("/dst/path", data)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(fakeContainer.StreamInCallCount()).Should(Equal(1))
			})

			itFailsWhenTheContainerIsNotFound(func() error {
				return container.StreamIn("/dst/path", nil)
			})

			Context("when copying in to the container fails", func() {
				BeforeEach(func() {
					fakeContainer.StreamInReturns(errors.New("oh no!"))
				})

				It("fails", func() {
开发者ID:julz,项目名称:garden-runc,代码行数:31,代码来源:request_handling_test.go

示例10:

			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,
			})
			Expect(err).ToNot(HaveOccurred())

			nothing := make([]byte, 1)
			n, err := out.Read(nothing)
			Expect(n).To(Equal(0))
			Expect(err).To(Equal(io.EOF))

			checkTree, err := destinationContainer.Run(garden.ProcessSpec{
				Path: "sh",
				Args: []string{
					"-exc",
					`
							find .
							test -e a
开发者ID:pcfdev-forks,项目名称:houdini,代码行数:31,代码来源:container_test.go

示例11: StreamToDestination

func StreamToDestination(c garden.Container, destPath string) error {
	tarFile, err := os.Open("../bin/consume.tar")
	Expect(err).ShouldNot(HaveOccurred())
	defer tarFile.Close()
	return c.StreamIn(garden.StreamInSpec{Path: destPath, TarStream: tarFile})
}
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:6,代码来源:limits_test.go

示例12:

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


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