本文整理汇总了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
}
示例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
}
示例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})
}
示例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()
},
),
)
示例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"} {
示例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{
示例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"))
示例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))
})
示例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() {
示例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
示例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})
}
示例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)