Exemplo n.º 1
0
				ghttp.RespondWith(http.StatusOK, `aaa`),
			)
		})

		AfterEach(func() {
			os.Remove(file.Name())
			server.Close()
		})

		var testFileIsEmpty = func() {
			fileInfo, _ := os.Lstat(file.Name())
			ExpectWithOffset(1, fileInfo.Size()).To(Equal(int64(0)))
		}

		It("returns an error if the product is nil", func() {
			err := api.Download(nil, file.Name())
			Expect(err).To(HaveOccurred())
			testFileIsEmpty()
		})

		It("returns an error if it can't get the product download url", func() {
			requester.GetProductDownloadUrlReturns("", errors.New("err"))
			err := api.Download(nil, file.Name())
			Expect(err).To(HaveOccurred())
			testFileIsEmpty()
		})

		It("downloads the data at the url", func() {
			requester.GetProductDownloadUrlReturns(server.URL(), nil)
			err := api.Download(&resource.ProductFile{}, file.Name())