Ejemplo n.º 1
0
			_, 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() {
			It("streams the directory", func() {
				_, stream, err := container.Run(warden.ProcessSpec{
					Script: `mkdir -p some-outer-dir/some-inner-dir; touch some-outer-dir/some-inner-dir/some-file;`,
				})

				Expect(*(<-stream).ExitStatus).To(Equal(uint32(0)))

				tarOutput, err := container.StreamOut("some-outer-dir/some-inner-dir")
				Ω(err).ShouldNot(HaveOccurred())

				tarReader := tar.NewReader(tarOutput)

				header, err := tarReader.Next()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(header.Name).Should(Equal("some-inner-dir/"))

				header, err = tarReader.Next()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(header.Name).Should(Equal("some-inner-dir/some-file"))
			})

			Context("with a trailing slash", func() {
				It("streams the contents of the directory", func() {
Ejemplo n.º 2
0
			It("returns the error", func() {
				_, err := container.StreamIn("to")
				Ω(err).Should(Equal(disaster))
			})
		})
	})

	Describe("StreamOut", func() {
		It("sends a stream out request", func() {
			fakeConnection.WhenStreamingOut = func(handle string, src string) (io.Reader, error) {
				Ω(src).Should(Equal("from"))
				return strings.NewReader("kewl"), nil
			}

			reader, err := container.StreamOut("from")
			bytes, err := ioutil.ReadAll(reader)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(string(bytes)).Should(Equal("kewl"))
		})

		Context("when streaming out fails", func() {
			disaster := errors.New("oh no!")

			BeforeEach(func() {
				fakeConnection.WhenStreamingOut = func(handle string, src string) (io.Reader, error) {
					return nil, disaster
				}
			})

			It("returns the error", func() {