Beispiel #1
0
import (
	"errors"
	"io"

	"github.com/cloudfoundry-incubator/switchboard/domain"
	"github.com/cloudfoundry-incubator/switchboard/domain/fakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/lager"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Bridge", func() {
	Describe("#Connect", func() {
		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)
		})
Beispiel #2
0
	Describe("HealthcheckUrl", func() {
		It("has the correct protocol, backend host and health check port", func() {
			healthcheckURL := backend.HealthcheckUrl()
			Expect(healthcheckURL).To(Equal("http://1.2.3.4:9902/status"))
		})
	})

	Describe("SeverConnections", func() {
		It("removes and closes all bridges", func() {
			backend.SeverConnections()
			Expect(bridges.RemoveAndCloseAllCallCount()).To(Equal(1))
		})
	})

	Describe("Bridge", func() {
		var backendConn *fakes.FakeConn
		var clientConn *fakes.FakeConn

		var dialErr error
		var dialedProtocol, dialedAddress string
		var bridge *fakes.FakeBridge
		var connectReadyChan, disconnectChan chan interface{}

		BeforeEach(func() {
			bridge = &fakes.FakeBridge{}

			connectReadyChan = make(chan interface{})
			disconnectChan = make(chan interface{})

			bridge.ConnectStub = func(connectReadyChan, disconnectChan chan interface{}) func() {
				return func() {