"github.com/cloudfoundry-incubator/ltc/exit_handler"
)

var _ = Describe("ExitHandler", func() {
	var (
		buffer      *gbytes.Buffer
		exitFunc    func(int)
		signalChan  chan os.Signal
		exitHandler exit_handler.ExitHandler
	)

	BeforeEach(func() {
		buffer = gbytes.NewBuffer()

		exitFunc = func(code int) {
			buffer.Write([]byte(fmt.Sprintf("Exit-Code=%d", code)))
		}

		signalChan = make(chan os.Signal)
		exitHandler = exit_handler.New(signalChan, exitFunc)
		go exitHandler.Run()

		exitHandler.OnExit(func() {
			buffer.Write([]byte("handler1 "))
		})

		exitHandler.OnExit(func() {
			buffer.Write([]byte("handler2 "))
		})
	})
		var shardID string

		BeforeEach(func() {
			SetLogger(&ginkgoLogger{})

			stdin = gbytes.NewBuffer()
			stdout = gbytes.NewBuffer()
			processor = &testProcessor{}

			shardID = uuid.NewRandom().String()
			go RunIO(processor, stdin, stdout)
		})

		It("received intialize action", func() {
			stdin.Write([]byte(fmt.Sprintf(`{"action": "initialize", "shardId": "%s"}`, shardID)))
			Eventually(stdout).Should(gbytes.Say(`{"action":"status","responseFor":"initialize"}`))
		})

		It("received processRecords action", func() {
			stdin.Write([]byte(fmt.Sprintf(`{"action": "processRecords", "records": [{"data": "data", "partitionKey": "pk1", "sequenceNumber": "001"}, {"data": "data", "partitionKey": "pk1", "sequenceNumber": "002"}]}`)))
			Eventually(stdout).Should(gbytes.Say(`{"action":"status","responseFor":"processRecords"}`))
		})

		It("received shutdown action", func() {
			stdin.Write([]byte(fmt.Sprintf(`{"action": "shutdown", "reason": "TERMINATE"}`)))
			Eventually(stdout).Should(gbytes.Say(`{"action":"status","responseFor":"shutdown"}`))
		})
	})
})
Example #3
0
		buffer *gbytes.Buffer

		readCloser *ReadCloser
	)

	BeforeEach(func() {
		eventStream = ""

		buffer = gbytes.NewBuffer()

		readCloser = NewReadCloser(buffer)
	})

	Describe("Next", func() {
		JustBeforeEach(func() {
			_, err := buffer.Write([]byte(eventStream))
			Ω(err).ShouldNot(HaveOccurred())
		})

		Context("when a comment appears on the stream", func() {
			BeforeEach(func() {
				eventStream += ":foo bar baz\n"
			})

			It("returns EOF", func() {
				_, err := readCloser.Next()
				Ω(err).Should(Equal(io.EOF))
			})

			Context("followed by an event", func() {
				BeforeEach(func() {
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"

	"github.com/cloudfoundry-incubator/lattice/ltc/test_helpers"
)

var _ = Describe("RegexSafeSay", func() {
	var outputBuffer *gbytes.Buffer

	BeforeEach(func() {
		outputBuffer = gbytes.NewBuffer()
	})

	Describe("Say", func() {
		BeforeEach(func() {
			outputBuffer.Write([]byte(`match this \|?-^$.(){}`))
		})
		It("matches with regex-escaped characters", func() {
			Expect(outputBuffer).To(test_helpers.Say(`match this \|?-^$.(){}`))
		})
		It("negated match", func() {
			Expect(outputBuffer).NotTo(test_helpers.Say("match that"))
		})
		Context("when format string is passed with arguments", func() {
			It("matches with regex-escaped characters", func() {
				Expect(outputBuffer).To(test_helpers.Say(`match %s \|?-^$.(){}`, "this"))
			})
		})
	})

	Describe("SayLine", func() {
	"github.com/onsi/gomega/gbytes"

	"github.com/cloudfoundry-incubator/lattice/ltc/test_helpers"
)

var _ = Describe("RegexSafeSay", func() {

	var gbytesBuffer *gbytes.Buffer

	BeforeEach(func() {
		gbytesBuffer = gbytes.NewBuffer()
	})

	Describe("Say", func() {
		It("matches with regex-escaped characters", func() {
			gbytesBuffer.Write([]byte(`match this \|?-^$.(){}`))

			Expect(gbytesBuffer).To(test_helpers.Say(`match this \|?-^$.(){}`))
		})

		It("negated match", func() {
			gbytesBuffer.Write([]byte("say that"))

			Expect(gbytesBuffer).ToNot(test_helpers.Say("different"))
		})
	})

	Describe("SayLine", func() {
		It("matches with regex-escaped characters", func() {
			gbytesBuffer.Write([]byte("sample\n"))