コード例 #1
0
ファイル: container_test.go プロジェクト: guanglinlv/garden
			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: "******",
				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
0
		})
	})

	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
0
ファイル: gardener_test.go プロジェクト: digideskio/guardian
		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: "******", 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: "******"}
				_, 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
0
ファイル: container_test.go プロジェクト: vito/gaol
				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
0
			})
		})

		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
0
							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
0
ファイル: streaming_test.go プロジェクト: digideskio/guardian
			process, err := container.Run(garden.ProcessSpec{
				User: "******",
				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: "******",
			})
			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("")