Example #1
0
			It("sends keep alive messages at the expected interval", func() {
				times := <-timesCh
				Expect(times[2]).To(BeTemporally("~", times[0].Add(200*time.Millisecond), 100*time.Millisecond))
			})
		})
	})

	Describe("LocalPortForward", func() {
		var (
			opts              *options.SSHOptions
			localForwardError error

			echoAddress  string
			echoListener *fake_net.FakeListener
			echoHandler  *fake_server.FakeConnectionHandler
			echoServer   *server.Server

			localAddress string

			realLocalListener net.Listener
			fakeLocalListener *fake_net.FakeListener
		)

		BeforeEach(func() {
			logger := lagertest.NewTestLogger("test")

			var err error
			realLocalListener, err = net.Listen("tcp", "127.0.0.1:0")
			Expect(err).NotTo(HaveOccurred())

			localAddress = realLocalListener.Addr().String()
Example #2
0
			srv = server.NewServer(logger, address, handler)
			srv.SetListener(fakeListener)
		})

		Context("when a listener has already been set", func() {
			It("returns an error", func() {
				listener := &fake_net.FakeListener{}
				err := srv.SetListener(listener)
				Expect(err).To(MatchError("Listener has already been set"))
			})
		})
	})

	Describe("Serve", func() {
		var fakeListener *fake_net.FakeListener
		var fakeConn *fake_net.FakeConn

		BeforeEach(func() {
			fakeListener = &fake_net.FakeListener{}
			fakeConn = &fake_net.FakeConn{}

			connectionCh := make(chan net.Conn, 1)
			connectionCh <- fakeConn

			fakeListener.AcceptStub = func() (net.Conn, error) {
				cx := connectionCh
				select {
				case conn := <-cx:
					return conn, nil
				default: