Esempio n. 1
0
		var bridge domain.Bridge
		var client, backend *fakes.FakeConn
		var logger lager.Logger

		BeforeEach(func() {
			logger = lagertest.NewTestLogger("Bridge test")
			backend = &fakes.FakeConn{}
			client = &fakes.FakeConn{}

			clientAddr := &fakes.FakeAddr{}
			backendAddr := &fakes.FakeAddr{}

			client.RemoteAddrReturns(clientAddr)
			backend.RemoteAddrReturns(backendAddr)

			bridge = domain.NewBridge(client, backend, logger)
		})

		Context("When operating normally", func() {

			It("forwards data from the client to backend", func() {
				expectedText := "hello"
				var copiedToBackend string
				clientReadCount := 0
				client.ReadStub = func(p []byte) (int, error) {
					if clientReadCount == 0 {
						copy(p, expectedText)
						clientReadCount++
						return len(expectedText), nil
					}
					return 0, io.EOF
Esempio n. 2
0
	Describe("Remove", func() {
		It("removes only the given bridge", func() {
			err := bridges.Remove(bridge2)
			Expect(err).NotTo(HaveOccurred())

			Expect(bridges.Contains(bridge1)).To(BeTrue())
			Expect(bridges.Contains(bridge2)).To(BeFalse())
			Expect(bridges.Contains(bridge3)).To(BeTrue())

			Expect(bridges.Size()).To(BeNumerically("==", 2))
		})

		Context("when the bridge cannot be found", func() {
			It("returns an error", func() {
				err := bridges.Remove(domain.NewBridge(&fakes.FakeConn{}, &fakes.FakeConn{}, nil))
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError("Bridge not found"))
			})
		})
	})

	Describe("RemoveAndCloseAll", func() {
		BeforeEach(func() {
			domain.BridgeProvider = func(_, _ net.Conn, logger lager.Logger) domain.Bridge {
				return &fakes.FakeBridge{}
			}
		})

		AfterEach(func() {
			domain.BridgeProvider = domain.NewBridge