<commit_before>package switchboard_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/pivotal-cf-experimental/switchboard"
	"github.com/pivotal-cf-experimental/switchboard/fakes"
	"github.com/pivotal-golang/lager"
)

var _ = Describe("Bridges", func() {
	var bridges Bridges

	BeforeEach(func() {
		bridges = NewBridges()
	})

	Describe("Remove", func() {
		var bridge1 *ConnectionBridge
		var bridge2 *ConnectionBridge
		var bridge3 *ConnectionBridge

		BeforeEach(func() {
			bridge1 = NewConnectionBridge(&fakes.FakeReadWriteCloser{}, &fakes.FakeReadWriteCloser{}, lager.NewLogger("test"))
			bridge2 = NewConnectionBridge(&fakes.FakeReadWriteCloser{}, &fakes.FakeReadWriteCloser{}, lager.NewLogger("test"))
			bridge3 = NewConnectionBridge(&fakes.FakeReadWriteCloser{}, &fakes.FakeReadWriteCloser{}, lager.NewLogger("test"))
			bridges.Add(bridge1)
			bridges.Add(bridge2)
			bridges.Add(bridge3)
		})

		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(Equal(2))
		})

		Context("when the bridge cannot be found", func() {
			It("returns an error", func() {
				err := bridges.Remove(NewConnectionBridge(&fakes.FakeReadWriteCloser{}, &fakes.FakeReadWriteCloser{}, lager.NewLogger("test")))
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError("Bridge not found"))
			})
		})
	})

	Describe("RemoveAndCloseAll", func() {
		var bridge1 *fakes.FakeBridge
		var bridge2 *fakes.FakeBridge
		var bridge3 *fakes.FakeBridge

		BeforeEach(func() {
			bridge1 = &fakes.FakeBridge{}
			bridge2 = &fakes.FakeBridge{}
			bridge3 = &fakes.FakeBridge{}
			bridges.Add(bridge1)
			bridges.Add(bridge2)
			bridges.Add(bridge3)
		})

		It("closes all bridges", func() {
			bridges.RemoveAndCloseAll()

			Expect(bridge1.CloseCallCount()).To(Equal(1))
			Expect(bridge2.CloseCallCount()).To(Equal(1))
			Expect(bridge3.CloseCallCount()).To(Equal(1))
		})

		It("removes all bridges", func() {<commit_msg>DRY test setup<commit_after>package switchboard_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/pivotal-cf-experimental/switchboard"
	"github.com/pivotal-cf-experimental/switchboard/fakes"
	"github.com/pivotal-golang/lager"
)

var _ = Describe("Bridges", func() {
	var bridges Bridges
	var bridge1 *fakes.FakeBridge
	var bridge2 *fakes.FakeBridge
	var bridge3 *fakes.FakeBridge

	BeforeEach(func() {
		bridges = NewBridges()

		bridge1 = &fakes.FakeBridge{}
		bridge2 = &fakes.FakeBridge{}
		bridge3 = &fakes.FakeBridge{}

		bridges.Add(bridge1)
		bridges.Add(bridge2)
		bridges.Add(bridge3)
	})

	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(Equal(2))
		})

		Context("when the bridge cannot be found", func() {
			It("returns an error", func() {
				err := bridges.Remove(NewConnectionBridge(&fakes.FakeReadWriteCloser{}, &fakes.FakeReadWriteCloser{}, lager.NewLogger("test")))
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError("Bridge not found"))
			})
		})
	})

	Describe("RemoveAndCloseAll", func() {
		It("closes all bridges", func() {
			bridges.RemoveAndCloseAll()

			Expect(bridge1.CloseCallCount()).To(Equal(1))
			Expect(bridge2.CloseCallCount()).To(Equal(1))
			Expect(bridge3.CloseCallCount()).To(Equal(1))
		})

		It("removes all bridges", func() {
{'fraction_non_alphanumeric': 0.16217643951399893, 'fraction_numerical': 0.012942419440042261, 'mean_word_length': 5.039872408293461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1724397', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1311, 'n_words': 196}