Exemplo n.º 1
0
func (s *SessionSuite) TestSendCheckedEarlyExit() {
	sessionCtx, _, session, transport := FakeSession(s.TestSuite, nil)

	stepper := util.NewStepper()
	randomSentinel = fakeSentinel("test-sentinel")

	go func() {
		for {
			stepper.Wait()
			<-transport.inchan
		}
	}()

	go func() {
		stepper.Step() // "foo"
		// Wait 5 milliseconds because Send has short delay
		stepper.Step(5) // "echo test-sentinel $?"
		transport.outchan <- "foo"
		transport.Cancel()
		transport.outchan <- "bar"
	}()

	exit, recv, err := session.SendChecked(sessionCtx, "foo")
	s.NotNil(err)
	s.Equal(-1, exit)
	s.Equal(2, len(recv), "should have gotten two lines of output")

}
Exemplo n.º 2
0
func (s *SessionSuite) TestSendChecked() {
	sessionCtx, _, session, transport := FakeSession(s.TestSuite, nil)

	stepper := util.NewStepper()
	go func() {
		transport.ListenAndRespond(0, []string{"foo\n"})
		stepper.Wait()
		transport.ListenAndRespond(1, []string{"bar\n"})
	}()

	// Success
	exit, recv, err := session.SendChecked(sessionCtx, "foo")
	s.Nil(err)
	s.Equal(0, exit)
	s.Equal("foo\n", recv[0])

	stepper.Step()
	// Non-zero Exit
	exit, recv, err = session.SendChecked(sessionCtx, "lala")
	s.NotNil(err)
	s.Equal(1, exit)
	s.Equal("bar\n", recv[0])
}