Beispiel #1
0
			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
				}

				backend.WriteStub = func(p []byte) (int, error) {
					copiedToBackend = string(p)
					return len(expectedText), nil
				}

				go bridge.Connect()
				defer bridge.Close()
				Eventually(client.ReadCallCount).Should(Equal(2))
				Eventually(backend.WriteCallCount).Should(Equal(1))
				Expect(copiedToBackend).To(Equal(expectedText))
			})

			It("forwards data from the backend to client", func() {
				expectedText := "echo: hello"
				var copiedToClient string

				backendReadCount := 0
				backend.ReadStub = func(p []byte) (int, error) {