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) clientConn, clientChannels, clientRequests, err := ssh.NewClientConn(clientNetConn, "0.0.0.0", clientConfig) Expect(err).NotTo(HaveOccurred()) client := ssh.NewClient(clientConn, clientChannels, clientRequests) client.Close() }) It("ensures the network connection is closed", func() { Eventually(fakeServerConnection.CloseCallCount).Should(BeNumerically(">=", 1)) }) }) })