) BeforeEach(func() { var err error client = &fakeclient.FakeClient{} factory := s3clicmd.NewFactory(client) cmd, err = factory.Create("put") Expect(err).ToNot(HaveOccurred()) }) Describe("Run", func() { Context("with enough arguments", func() { It("uploads blob", func() { err := cmd.Run([]string{"../../fixtures/cat.jpg", "my-cat.jpg"}) Expect(err).ToNot(HaveOccurred()) file := client.PutReaderReader.(*os.File) Expect(client.PutReaderPath).To(Equal("my-cat.jpg")) Expect(file.Name()).To(Equal("../../fixtures/cat.jpg")) Expect(client.PutReaderLength).To(Equal(int64(1718186))) Expect(client.PutReaderContentType).To(Equal("application/octet-stream")) Expect(client.PutReaderPerm).To(Equal(amzs3.BucketOwnerFull)) }) }) Context("with not enough arguments", func() { It("returns error", func() { err := cmd.Run([]string{"my-cat.jpg"}) Expect(err).To(HaveOccurred())
cmd, err = factory.Create("get") Expect(err).ToNot(HaveOccurred()) }) Describe("Run", func() { Context("with enough arguments", func() { It("downloads blob", func() { fixtureCatPath := "../../fixtures/cat.jpg" tmpCatPath := "../../../tmp/cat.jpg" fixtureCatFile, err := os.Open(fixtureCatPath) Expect(err).ToNot(HaveOccurred()) client.GetReaderReadCloser = fixtureCatFile err = cmd.Run([]string{"my-cat.jpg", tmpCatPath}) Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpCatPath) Expect(client.GetReaderPath).To(Equal("my-cat.jpg")) tmpCatFile, err := os.Open(tmpCatPath) Expect(err).ToNot(HaveOccurred()) tmpCatStats, err := tmpCatFile.Stat() Expect(err).ToNot(HaveOccurred()) Expect(tmpCatStats.Size()).To(Equal(int64(1718186))) }) })