github.com/benthosdev/benthos/v4@v4.27.0/internal/impl/kafka/input_sarama_kafka_test.go (about) 1 package kafka_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/Jeffail/gabs/v2" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/benthosdev/benthos/v4/internal/component/input" 12 "github.com/benthosdev/benthos/v4/internal/component/testutil" 13 "github.com/benthosdev/benthos/v4/internal/manager/mock" 14 ) 15 16 func parseYAMLInputConf(t testing.TB, formatStr string, args ...any) (conf input.Config) { 17 t.Helper() 18 var err error 19 conf, err = testutil.InputFromYAML(fmt.Sprintf(formatStr, args...)) 20 require.NoError(t, err) 21 return 22 } 23 24 func TestKafkaBadParams(t *testing.T) { 25 testCases := []struct { 26 name string 27 topics []string 28 errStr string 29 }{ 30 { 31 name: "mixing consumer types", 32 topics: []string{"foo", "foo:1"}, 33 errStr: "it is not currently possible to include balanced and explicit partition topics in the same kafka input", 34 }, 35 { 36 name: "too many partitions", 37 topics: []string{"foo:1:2:3"}, 38 errStr: "topic 'foo:1:2:3' is invalid, only one partition and an optional offset should be specified", 39 }, 40 { 41 name: "bad range", 42 topics: []string{"foo:1-2-3"}, 43 errStr: "partition '1-2-3' is invalid, only one range can be specified", 44 }, 45 } 46 47 for _, test := range testCases { 48 test := test 49 t.Run(test.name, func(t *testing.T) { 50 conf := parseYAMLInputConf(t, ` 51 kafka: 52 addresses: [ example.com:1234 ] 53 topics: %v 54 `, gabs.Wrap(test.topics).String()) 55 56 _, err := mock.NewManager().NewInput(conf) 57 require.Error(t, err) 58 assert.Contains(t, err.Error(), test.errStr) 59 }) 60 } 61 }