當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeConn.ReadReturns方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_net.FakeConn.ReadReturns方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeConn.ReadReturns方法的具體用法?Golang FakeConn.ReadReturns怎麽用?Golang FakeConn.ReadReturns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_net.FakeConn的用法示例。


在下文中一共展示了FakeConn.ReadReturns方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

			It("closes the listener when the client is closed", func() {
				Eventually(fakeListenerFactory.ListenCallCount).Should(Equal(1))
				Eventually(fakeLocalListener.AcceptCallCount).Should(Equal(1))

				originalCloseCount := fakeLocalListener.CloseCallCount()
				err := secureShell.Close()
				Expect(err).NotTo(HaveOccurred())
				Expect(fakeLocalListener.CloseCallCount()).Should(Equal(originalCloseCount + 1))
			})
		})

		Context("when accept fails", func() {
			var fakeConn *fake_net.FakeConn
			BeforeEach(func() {
				fakeConn = &fake_net.FakeConn{}
				fakeConn.ReadReturns(0, io.EOF)

				fakeListenerFactory.ListenReturns(fakeLocalListener, nil)
			})

			Context("with a permanent error", func() {
				BeforeEach(func() {
					fakeLocalListener.AcceptReturns(nil, errors.New("boom"))
				})

				It("stops trying to accept connections", func() {
					Eventually(fakeLocalListener.AcceptCallCount).Should(Equal(1))
					Consistently(fakeLocalListener.AcceptCallCount).Should(Equal(1))
					Expect(fakeLocalListener.CloseCallCount()).To(Equal(1))
				})
			})
開發者ID:vframbach,項目名稱:cli,代碼行數:31,代碼來源:ssh_test.go

示例2:

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		serverSSHConfig = &ssh.ServerConfig{
			NoClientAuth: true,
		}
		serverSSHConfig.AddHostKey(TestHostKey)
	})

	Describe("HandleConnection", func() {
		var fakeConn *fake_net.FakeConn

		Context("when the function returns", func() {
			BeforeEach(func() {
				fakeConn = &fake_net.FakeConn{}
				fakeConn.ReadReturns(0, errors.New("oops"))

				sshd = daemon.New(logger, serverSSHConfig, nil, nil)
			})

			It("closes the connection", func() {
				sshd.HandleConnection(fakeConn)
				Expect(fakeConn.CloseCallCount()).To(BeNumerically(">=", 1))
			})
		})

		Context("when an ssh client connects", func() {
			var (
				serverNetConn net.Conn
				clientNetConn net.Conn
開發者ID:benjaminharnett,項目名稱:diego-ssh,代碼行數:29,代碼來源:daemon_test.go


注:本文中的github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_net.FakeConn.ReadReturns方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。