forked from lovoo/goka
/
doc.go
47 lines (37 loc) · 1.41 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
This package provides a kafka mock that allows integration testing of goka processors.
Usage
Simply append a tester option when creating the processor for testing.
Usually it makes sense to move the processor creation to a function that accepts
extra options. That way the test can use exactly the same processor setup.
// creates the processor defining its group graph
func createProcessor(brokers []string, options ...goka.ProcessorOption) *goka.Processor{
return goka.NewProcessor(brokers, goka.DefineGroup("group",
// some group definitions
options...,
),
)
}
In the main function we would run the processor like this:
func main(){
proc := createProcessor([]string{"broker1:9092"})
proc.Run(ctx.Background())
}
And in the unit test something like:
func TestProcessor(t *testing.T){
// create tester
tester := tester.New(t)
// create the processor
proc := createProcessor(nil, goka.WithTester(tester))
// .. do extra initialization if necessary
go proc.Run(ctx.Background())
// execute the actual test
tester.Consume("input-topic", "key", "value")
value := tester.TableValue("group-table", "key")
if value != expected{
t.Fatalf("got unexpected table value")
}
}
See https://github.com/lovoo/goka/tree/master/examples/testing for a full example
*/
package tester