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


Golang fake_net.FakeConn類代碼示例

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


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

示例1:

					BeforeEach(func() {
						daemonAuthenticator.AuthenticateReturns(nil, errors.New("go away"))
					})

					It("closes the connection", func() {
						Eventually(client.Wait).Should(Equal(io.EOF))
					})

					It("logs the failure", func() {
						Eventually(logger).Should(gbytes.Say(`new-client-conn.handshake-failed`))
					})
				})
			})

			Context("when HandleConnection returns", func() {
				var fakeServerConnection *fake_net.FakeConn

				BeforeEach(func() {
					proxySSHConfig.NoClientAuth = true
					daemonSSHConfig.NoClientAuth = true
				})

				JustBeforeEach(func() {
					clientNetConn, serverNetConn := test_helpers.Pipe()

					fakeServerConnection = &fake_net.FakeConn{}
					fakeServerConnection.ReadStub = serverNetConn.Read
					fakeServerConnection.WriteStub = serverNetConn.Write
					fakeServerConnection.CloseStub = serverNetConn.Close

					go sshProxy.HandleConnection(fakeServerConnection)
開發者ID:sykesm,項目名稱:diego-ssh,代碼行數:31,代碼來源:proxy_test.go

示例2:

				fakeLocalListener.AcceptReturns(nil, errors.New("not accepting and connections"))
			})

			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))
開發者ID:vframbach,項目名稱:cli,代碼行數:31,代碼來源:ssh_test.go

示例3:

		logger lager.Logger
		sshd   *daemon.Daemon

		serverSSHConfig *ssh.ServerConfig
	)

	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))
			})
		})
開發者ID:benjaminharnett,項目名稱:diego-ssh,代碼行數:30,代碼來源:daemon_test.go


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