func TestLastItemCollector(t *testing.T) { Convey("Given I have a context", t, func() { context := rivers.NewContext() Convey("And a stream of data", func() { in, out := stream.New(2) out <- 1 out <- 2 close(out) Convey("When I apply the collector consumer", func() { var number int consumer := consumers.LastItemCollector(&number) consumer.Attach(context) consumer.Consume(in) Convey("Then data is collected out of the stream", func() { So(number, ShouldResemble, 2) _, opened := <-in So(opened, ShouldBeFalse) }) }) Convey("When I apply the collector consuming data into a non pointer", func() { var number int collect := func() { consumers.LastItemCollector(number) } Convey("Then it panics", func() { So(collect, ShouldPanicWith, consumers.ErrNoSuchPointer) }) }) }) }) }
func (pipeline *Pipeline) CollectLastAs(data interface{}) error { return pipeline.Then(consumers.LastItemCollector(data)) }