示例#1
0
				runCurlWithInputs([]string{"--output", tempFile.Name(), "/foo"})
				contents, err := ioutil.ReadAll(tempFile)
				Expect(err).ToNot(HaveOccurred())
				Expect(string(contents)).To(Equal("hai"))
			})
		})

		It("saves the body of the response to the given filepath if it doesn't exists", func() {
			fileutils.TempDir("poor-mans-dir", func(tmpDir string, err error) {
				Expect(err).ToNot(HaveOccurred())
				curlRepo.ResponseBody = "hai"

				filePath := filepath.Join(tmpDir, "subdir1", "banana.txt")
				runCurlWithInputs([]string{"--output", filePath, "/foo"})

				file, err := os.Open(filePath)
				Expect(err).ToNot(HaveOccurred())

				contents, err := ioutil.ReadAll(file)
				Expect(err).ToNot(HaveOccurred())
				Expect(string(contents)).To(Equal("hai"))
			})
		})
	})

	It("makes a post request given -X", func() {
		runCurlWithInputs([]string{"-X", "post", "/foo"})

		Expect(curlRepo.Method).To(Equal("post"))
		Expect(ui.Outputs()).ToNot(ContainSubstrings([]string{"FAILED"}))
	})
示例#2
0
			fileContents, _ := ioutil.ReadAll(file)
			Expect(fileContents).To(ContainSubstring("Hello World"))
		})
	})

	It("creates the file with 0600 permission", func() {
		// cannot use fileutils.TempFile because it sets the permissions to 0600
		// itself
		fileutils.TempDir("trace_test", func(tmpDir string, err error) {
			Expect(err).ToNot(HaveOccurred())

			fileName := path.Join(tmpDir, "trace_test")
			logger := NewLogger(buffer, true, fileName, "")
			logger.Print("Hello World")

			stat, err := os.Stat(fileName)
			Expect(err).ToNot(HaveOccurred())
			if runtime.GOOS == "windows" {
				Expect(stat.Mode().String()).To(Equal(os.FileMode(0666).String()))
			} else {
				Expect(stat.Mode().String()).To(Equal(os.FileMode(0600).String()))
			}
		})
	})

	It("returns a logger that writes to STDOUT and a file when verbose is set and config.trace is a path", func() {
		fileutils.TempFile("trace_test", func(file *os.File, err error) {
			logger := NewLogger(buffer, true, "", file.Name())

			logger.Print("Hello World")
示例#3
0
				}))
			})
		})

		// NB: on windows, you can never rely on the size of a directory being zero
		// see: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx
		// and: https://www.pivotaltracker.com/story/show/70470232
		It("always sets the size of directories to zero bytes", func() {
			fileutils.TempDir("something", func(tempdir string, err error) {
				Expect(err).ToNot(HaveOccurred())

				err = os.Mkdir(filepath.Join(tempdir, "nothing"), 0600)
				Expect(err).ToNot(HaveOccurred())

				files, err := appFiles.AppFilesInDir(tempdir)
				Expect(err).ToNot(HaveOccurred())

				sizes := []int64{}
				for _, file := range files {
					sizes = append(sizes, file.Size)
				}

				Expect(sizes).To(Equal([]int64{0}))
			})
		})
	})

	Describe("CopyFiles", func() {
		It("copies only the files specified", func() {
			copyDir := filepath.Join(fixturePath, "app-copy-test")

			filesToCopy := []models.AppFileFields{
示例#4
0
			compressedFileSize := fileStat.Size()
			Expect(compressedFileSize).To(BeNumerically("<", originalFileSize))
		})

		It("returns an error when zipping fails", func() {
			zipper := ApplicationZipper{}
			err := zipper.Zip("/a/bogus/directory", zipFile)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("open /a/bogus/directory"))
		})

		It("returns an error when the directory is empty", func() {
			fileutils.TempDir("zip_test", func(emptyDir string, err error) {
				zipper := ApplicationZipper{}
				err = zipper.Zip(emptyDir, zipFile)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("is empty"))
			})
		})
	})

	Describe("IsZipFile", func() {
		var (
			inDir, outDir string
			zipper        ApplicationZipper
		)

		AfterEach(func() {
			os.RemoveAll(inDir)
			os.RemoveAll(outDir)
		})