Ejemplo n.º 1
0
	BeforeEach(func() {
		mockSessionFactory := &mocks.FakeSSHSessionFactory{}
		client = &sshapi.Client{
			SSHSessionFactory: mockSessionFactory,
			Stdin:             &bytes.Buffer{},
			Stdout:            &bytes.Buffer{},
			Stderr:            &bytes.Buffer{},
		}
		mockSession = &mocks.FakeSSHSession{}
		mockSession.StdinPipeReturns(&mockConn{Writer: &bytes.Buffer{}}, nil)
		mockSession.StdoutPipeReturns(&bytes.Buffer{}, nil)
		mockSession.StderrPipeReturns(&bytes.Buffer{}, nil)
		mockSessionFactory.NewReturns(mockSession, nil)
		var err error
		session, err = client.Open(0, 0, false)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("#KeepAlive", func() {
		It("should send a request when the ticker ticks", func() {
			ticker := make(chan time.Time)
			session.KeepAliveTicker.C = ticker

			stopChan := session.KeepAlive()
			Consistently(mockSession.SendRequestCallCount).Should(Equal(0))
			ticker <- time.Time{}
			Eventually(mockSession.SendRequestCallCount).Should(Equal(1))
			ticker <- time.Time{}
			Eventually(mockSession.SendRequestCallCount).Should(Equal(2))
			stopChan <- struct{}{}
Ejemplo n.º 2
0
		It("should open a new session", func() {
			os.Setenv("TERM", "some term")

			client.Stdin = bytes.NewBufferString("some client in data")
			client.Stdout = &bytes.Buffer{}
			client.Stderr = &bytes.Buffer{}
			mockSessionStdinBuffer := &bytes.Buffer{}
			mockSessionStdin := &mockConn{Writer: mockSessionStdinBuffer}
			mockSessionStdout := bytes.NewBufferString("some session out data")
			mockSessionStderr := bytes.NewBufferString("some session err data")
			mockSession.StdinPipeReturns(mockSessionStdin, nil)
			mockSession.StdoutPipeReturns(mockSessionStdout, nil)
			mockSession.StderrPipeReturns(mockSessionStderr, nil)

			_, err := client.Open(100, 200, true)
			Expect(err).NotTo(HaveOccurred())

			Expect(mockSession.RequestPtyCallCount()).To(Equal(1))
			termType, height, width, modes := mockSession.RequestPtyArgsForCall(0)
			Expect(termType).To(Equal("some term"))
			Expect(height).To(Equal(200))
			Expect(width).To(Equal(100))
			Expect(modes[ssh.ECHO]).To(Equal(uint32(1)))
			Expect(modes[ssh.TTY_OP_ISPEED]).To(Equal(uint32(115200)))
			Expect(modes[ssh.TTY_OP_OSPEED]).To(Equal(uint32(115200)))

			Eventually(mockSessionStdinBuffer.String).Should(Equal("some client in data"))
			Eventually(client.Stdout.(*bytes.Buffer).String).Should(Equal("some session out data"))
			Eventually(client.Stderr.(*bytes.Buffer).String).Should(Equal("some session err data"))
			Eventually(func() bool { return mockSessionStdin.closed }).Should(BeTrue())