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

     1  package reader
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  	"gopkg.in/yaml.v3"
     9  )
    10  
    11  func TestKafkaDeprecationCheck(t *testing.T) {
    12  	testCases := []struct {
    13  		name string
    14  		conf string
    15  		exp  bool
    16  	}{
    17  		{
    18  			name: "all defaults",
    19  			conf: `{}`,
    20  			exp:  false,
    21  		},
    22  		{
    23  			name: "has both topics and topic",
    24  			conf: `topic: foobar
    25  topics: [ foo, bar ]`,
    26  			exp: true,
    27  		},
    28  		{
    29  			name: "has just topics",
    30  			conf: `topics: [ foo, bar ]
    31  key: fookey`,
    32  			exp: false,
    33  		},
    34  		{
    35  			name: "has topic and partition",
    36  			conf: `topic: foobar
    37  partition: 0`,
    38  			exp: true,
    39  		},
    40  		{
    41  			name: "has topic",
    42  			conf: `topic: foobar
    43  key: fookey`,
    44  			exp: true,
    45  		},
    46  		{
    47  			name: "has partition",
    48  			conf: `partition: 0
    49  key: fookey`,
    50  			exp: true,
    51  		},
    52  	}
    53  
    54  	for _, test := range testCases {
    55  		test := test
    56  		t.Run(test.name, func(t *testing.T) {
    57  			var conf KafkaConfig
    58  			require.NoError(t, yaml.Unmarshal([]byte(test.conf), &conf))
    59  			assert.Equal(t, test.exp, conf.IsDeprecated())
    60  		})
    61  	}
    62  }