github.com/Jeffail/benthos/v3@v3.65.0/lib/processor/group_by_value_test.go (about) 1 package processor 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/Jeffail/benthos/v3/lib/log" 8 "github.com/Jeffail/benthos/v3/lib/message" 9 "github.com/Jeffail/benthos/v3/lib/metrics" 10 ) 11 12 //------------------------------------------------------------------------------ 13 14 func TestGroupByValueBasic(t *testing.T) { 15 conf := NewConfig() 16 conf.Type = TypeGroupByValue 17 conf.GroupByValue.Value = "${!json(\"foo\")}" 18 19 proc, err := New(conf, nil, log.Noop(), metrics.Noop()) 20 if err != nil { 21 t.Fatal(err) 22 } 23 24 exp := [][][]byte{ 25 { 26 []byte(`{"foo":0,"bar":0}`), 27 []byte(`{"foo":0,"bar":7}`), 28 }, 29 { 30 []byte(`{"foo":3,"bar":1}`), 31 }, 32 { 33 []byte(`{"bar":2}`), 34 }, 35 { 36 []byte(`{"foo":2,"bar":3}`), 37 }, 38 { 39 []byte(`{"foo":4,"bar":4}`), 40 }, 41 { 42 []byte(`{"foo":1,"bar":5}`), 43 []byte(`{"foo":1,"bar":6}`), 44 []byte(`{"foo":1,"bar":8}`), 45 }, 46 } 47 act := [][][]byte{} 48 49 input := message.New([][]byte{ 50 []byte(`{"foo":0,"bar":0}`), 51 []byte(`{"foo":3,"bar":1}`), 52 []byte(`{"bar":2}`), 53 []byte(`{"foo":2,"bar":3}`), 54 []byte(`{"foo":4,"bar":4}`), 55 []byte(`{"foo":1,"bar":5}`), 56 []byte(`{"foo":1,"bar":6}`), 57 []byte(`{"foo":0,"bar":7}`), 58 []byte(`{"foo":1,"bar":8}`), 59 }) 60 msgs, res := proc.ProcessMessage(input) 61 if res != nil { 62 t.Fatal(res.Error()) 63 } 64 65 for _, msg := range msgs { 66 act = append(act, message.GetAllBytes(msg)) 67 } 68 if !reflect.DeepEqual(exp, act) { 69 t.Errorf("Wrong result: %s != %s", act, exp) 70 } 71 } 72 73 //------------------------------------------------------------------------------