Esempio n. 1
0
				newChan.AcceptReturns(sourceChannel, sourceReqChan, nil)

				targetConn.OpenChannelReturns(targetChannel, targetReqChan, nil)

				newChanChan <- newChan
			})

			AfterEach(func() {
				close(newChanChan)
			})

			It("forwards the NewChannel request to the target", func() {
				Eventually(targetConn.OpenChannelCallCount).Should(Equal(1))
				Consistently(targetConn.OpenChannelCallCount).Should(Equal(1))

				channelType, extraData := targetConn.OpenChannelArgsForCall(0)
				Expect(channelType).To(Equal("test"))
				Expect(extraData).To(Equal([]byte("extra-data")))
			})

			Context("when the target accepts the connection", func() {
				It("accepts the source request", func() {
					Eventually(newChan.AcceptCallCount).Should(Equal(1))
				})

				Context("when the source channel has data available", func() {
					BeforeEach(func() {
						sourceChannel.ReadStub = func(dest []byte) (int, error) {
							if cap(dest) >= 3 {
								copy(dest, []byte("abc"))
								return 3, io.EOF