func streamin(ctr garden.Container, archive string) { for i := 0; i < 20; i++ { By(fmt.Sprintf("preparing stream %d for handle %s", i, ctr.Handle())) // Stream in a tar file to ctr var tarStream io.Reader pwd, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) tgzPath := path.Join(pwd, archive) tgz, err := os.Open(tgzPath) Expect(err).ToNot(HaveOccurred()) tarStream, err = gzip.NewReader(tgz) Expect(err).ToNot(HaveOccurred()) By(fmt.Sprintf("starting stream %d for handle: %s", i, ctr.Handle())) Expect(ctr.StreamIn(garden.StreamInSpec{ User: "******", Path: fmt.Sprintf("/root/stream-file-%d", i), TarStream: tarStream, })).To(Succeed()) By(fmt.Sprintf("stream %d done for handle: %s", i, ctr.Handle())) tgz.Close() } }
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: "******", 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{
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: "******", 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: "******", Path: "sh", Args: []string{"-c", "mkdir -p /root/documents/some/reports && echo hello > /root/documents/some/reports/test"}, }, ginkgoIO)