本文整理汇总了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))
})
})
示例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