Example #1
0
			timeMessage *scp.TimeMessage

			expectedModificationTime time.Time
			expectedAccessTime       time.Time
		)

		BeforeEach(func() {
			fileInfo, ferr := os.Stat(tempFile)
			Expect(ferr).NotTo(HaveOccurred())

			expectedAccessTime, ferr = atime.AccessTime(fileInfo)
			Expect(ferr).NotTo(HaveOccurred())

			expectedModificationTime = fileInfo.ModTime()

			timeMessage = scp.NewTimeMessage(fileInfo)
		})

		It("acquires the correct modification time", func() {
			Expect(timeMessage.ModificationTime()).To(Equal(expectedModificationTime))
		})

		It("acquires the correct access time", func() {
			Expect(timeMessage.AccessTime()).To(Equal(expectedAccessTime))
		})
	})

	Context("when sending the time information to an scp sink", func() {
		var timeMessage *scp.TimeMessage

		BeforeEach(func() {
Example #2
0
			Expect(fileInfo.Mode()).To(Equal(os.FileMode(0444)))
		})

		It("sets the timestamp of the file if present", func() {
			stdin := &bytes.Buffer{}
			stdout := &bytes.Buffer{}
			stderr := &bytes.Buffer{}

			stdin.WriteString("C0444 5 hello.txt\n")
			stdin.WriteString("hello")
			stdin.WriteByte(0)

			tempFileInfo, err := os.Stat(tempFile)
			Expect(err).NotTo(HaveOccurred())
			timestamp := scp.NewTimeMessage(tempFileInfo)

			testCopier = newTestCopier(stdin, stdout, stderr, true)
			err = testCopier.ReceiveFile(tempDir, true, timestamp)
			Expect(err).NotTo(HaveOccurred())

			fileInfo, err := os.Stat(filepath.Join(tempDir, "hello.txt"))
			Expect(err).NotTo(HaveOccurred())

			Expect(fileInfo.ModTime()).To(Equal(tempFileInfo.ModTime()))

			fileAtime, err := atime.AccessTime(fileInfo)
			Expect(err).NotTo(HaveOccurred())

			tempAtime, err := atime.AccessTime(tempFileInfo)
			Expect(err).NotTo(HaveOccurred())