Пример #1
0
	})

	Context("when receiving a time message from an scp source", func() {
		var timeMessage *scp.TimeMessage

		BeforeEach(func() {
			timeMessage = &scp.TimeMessage{}
		})

		It("creates a time message with the appropriate information", func() {
			stdin := strings.NewReader("T123456789 0 987654321 0\n")
			stdout := &bytes.Buffer{}
			stderr := &bytes.Buffer{}
			session := scp.NewSession(stdin, stdout, stderr, true, logger)

			err := timeMessage.Receive(session)
			Expect(err).NotTo(HaveOccurred())

			Expect(timeMessage.ModificationTime()).To(Equal(time.Unix(123456789, 0)))
			Expect(timeMessage.AccessTime()).To(Equal(time.Unix(987654321, 0)))
		})

		It("sends a confirmation after the message is received", func() {
			reader := strings.NewReader("T123456789 0 987654321 0\n")
			stdin := &fake_io.FakeReader{}
			stdout := &fake_io.FakeWriter{}
			stderr := &bytes.Buffer{}
			session := scp.NewSession(stdin, stdout, stderr, true, logger)

			stdin.ReadStub = reader.Read
			stdout.WriteStub = func(message []byte) (int, error) {
Пример #2
0
					done := make(chan struct{})
					go func() {
						err := secureCopier.Copy()
						Expect(err).NotTo(HaveOccurred())
						close(done)
					}()

					_, err = stdinSource.Write([]byte{0})
					Expect(err).NotTo(HaveOccurred())

					session := scp.NewSession(stdoutSource, stdinSource, nil, preserveTimestamps, logger)

					var timestampMessage *scp.TimeMessage
					if preserveTimestamps {
						timestampMessage = &scp.TimeMessage{}
						err = timestampMessage.Receive(session)
						Expect(err).NotTo(HaveOccurred())
					}

					testCopier = newTestCopier(stdoutSource, stdinSource, nil, preserveTimestamps)
					err = testCopier.ReceiveFile(targetDir, true, timestampMessage)
					Expect(err).NotTo(HaveOccurred())
					Eventually(done).Should(BeClosed())

					sourceFileInfo, err = os.Stat(generatedTextFile)
					Expect(err).NotTo(HaveOccurred())
				})

				It("sends the file", func() {
					compareFile(filepath.Join(targetDir, sourceFileInfo.Name()), generatedTextFile, preserveTimestamps)
				})