Context("when given multiple functions", func() {

		var (
			fakeSetupBuilder SetupFunctionBuilder
			fakeSetup        SetupFunction
			functionInvoker  FunctionInvoker
		)

		BeforeEach(func() {
			functionInvoker = NewFunctionInvoker()
			fakeSetupBuilder = func(name string, f func(SetupFunction), c chan FunctionInfo) SetupFunction {
				return fakeSetup
			}

			fakeSetup = mocks.NewMockSetupFunction(nil, nil)
			rand.Seed(time.Now().UnixNano())
			fakeSetup.SetName(strconv.Itoa(rand.Int()))
		})

		It("invokes each function once initially", func(done Done) {
			defer close(done)

			countChan := make(chan interface{})
			fake := func(sf SetupFunction) {
				countChan <- nil
			}

			functionInvoker(fakeSetupBuilder, fake, fake, fake)
			for i := 0; i < 3; i++ {
				<-countChan
Exemple #2
0
	"net/http/httptest"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Web Crawler", func() {
	var in chan encoding.BinaryMarshaler
	var out chan encoding.BinaryMarshaler
	var sf types.SetupFunction

	BeforeEach(func() {
		in = make(chan encoding.BinaryMarshaler)
		out = make(chan encoding.BinaryMarshaler)
		sf = mocks.NewMockSetupFunction(in, out)
	})

	Context("UrlProducer", func() {
		It("should only output new URLs", func(done Done) {
			defer close(done)
			go UrlProducer(sf, "parent")

			in <- NewStringMarshaler("url-a")
			Expect(ToString(<-out)).To(Equal("url-a"))

			in <- NewStringMarshaler("url-b")
			Expect(ToString(<-out)).To(Equal("url-b"))

			in <- NewStringMarshaler("url-a")
			Expect(timedReceive(out)).To(BeNil())