Exemplo n.º 1
0
				case "drippy/result.json":
					return fakeMetadataReader, nil
				case "no-such-droplet/droplet.tgz":
					return nil, errors.New("some missing droplet error")
				case "no-such-metadata/droplet.tgz":
					return fakeDropletReader, nil
				case "no-such-metadata/result.json":
					return nil, errors.New("some missing metadata error")
				default:
					return nil, errors.New("fake GetReader called with invalid arguments")
				}
			}
		})

		It("returns IO readers for the droplet and its metadata", func() {
			dropletReader, metadataReader, err := dropletRunner.ExportDroplet("drippy")
			defer dropletReader.Close()
			defer metadataReader.Close()
			Expect(err).NotTo(HaveOccurred())
			Expect(ioutil.ReadAll(dropletReader)).To(BeEquivalentTo("some droplet reader"))
			Expect(ioutil.ReadAll(metadataReader)).To(BeEquivalentTo("some metadata reader"))
		})

		Context("when the droplet name does not have an associated droplet", func() {
			It("returns an error", func() {
				_, _, err := dropletRunner.ExportDroplet("no-such-droplet")
				Expect(err).To(MatchError("droplet not found: some missing droplet error"))
			})
		})

		Context("when the droplet name does not have an associated metadata", func() {
			fakeDropletReader := ioutil.NopCloser(strings.NewReader("some droplet reader"))

			fakeBlobStore.DownloadStub = func(path string) (io.ReadCloser, error) {
				switch path {
				case "drippy-droplet.tgz":
					return fakeDropletReader, nil
				case "no-such-droplet-droplet.tgz":
					return nil, errors.New("some missing droplet error")
				default:
					return nil, errors.New("fake GetReader called with invalid arguments")
				}
			}
		})

		It("returns IO readers for the droplet", func() {
			dropletReader, err := dropletRunner.ExportDroplet("drippy")
			defer dropletReader.Close()
			Expect(err).NotTo(HaveOccurred())
			Expect(ioutil.ReadAll(dropletReader)).To(BeEquivalentTo("some droplet reader"))
		})

		Context("when the droplet name does not have an associated droplet", func() {
			It("returns an error", func() {
				_, err := dropletRunner.ExportDroplet("no-such-droplet")
				Expect(err).To(MatchError("droplet not found: some missing droplet error"))
			})
		})
	})

	Describe("ImportDroplet", func() {
		var tmpDir, dropletPathArg string