github.com/Jeffail/benthos/v3@v3.65.0/lib/input/kafka_test.go (about)

     1  package input
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/Jeffail/benthos/v3/lib/log"
     7  	"github.com/Jeffail/benthos/v3/lib/metrics"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestKafkaBadParams(t *testing.T) {
    12  	testCases := []struct {
    13  		name   string
    14  		topics []string
    15  		errStr string
    16  	}{
    17  		{
    18  			name:   "mixing consumer types",
    19  			topics: []string{"foo", "foo:1"},
    20  			errStr: "failed to create input 'kafka': it is not currently possible to include balanced and explicit partition topics in the same kafka input",
    21  		},
    22  		{
    23  			name:   "too many partitions",
    24  			topics: []string{"foo:1:2:3"},
    25  			errStr: "failed to create input 'kafka': topic 'foo:1:2:3' is invalid, only one partition should be specified and the same topic can be listed multiple times, e.g. use `foo:0,foo:1` not `foo:0:1`",
    26  		},
    27  		{
    28  			name:   "bad range",
    29  			topics: []string{"foo:1-2-3"},
    30  			errStr: "failed to create input 'kafka': partition '1-2-3' is invalid, only one range can be specified",
    31  		},
    32  	}
    33  
    34  	for _, test := range testCases {
    35  		test := test
    36  		t.Run(test.name, func(t *testing.T) {
    37  			conf := NewConfig()
    38  			conf.Type = TypeKafka
    39  			conf.Kafka.Addresses = []string{"example.com:1234"}
    40  			conf.Kafka.Topics = test.topics
    41  
    42  			_, err := New(conf, nil, log.Noop(), metrics.Noop())
    43  			assert.EqualError(t, err, test.errStr)
    44  		})
    45  	}
    46  }