2023-05-04 17:28:53 +02:00
|
|
|
import { convertKafkaJSHeadersToRdKafkaHeaders } from '../../src/utils/db/kafka-producer-wrapper'
|
|
|
|
|
|
|
|
test('can convert from KafkaJS headers to rdkafka headers', () => {
|
2023-06-20 14:29:26 +02:00
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders()).toEqual(undefined)
|
2023-05-04 17:28:53 +02:00
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({})).toEqual([])
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: 'bar' })).toEqual([{ foo: Buffer.from('bar') }])
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: ['bar', 'baz'] })).toEqual([
|
|
|
|
{ foo: Buffer.from('bar') },
|
|
|
|
{ foo: Buffer.from('baz') },
|
|
|
|
])
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: ['bar', 'baz'], qux: 'quux' })).toEqual([
|
|
|
|
{ foo: Buffer.from('bar') },
|
|
|
|
{ foo: Buffer.from('baz') },
|
|
|
|
{ qux: Buffer.from('quux') },
|
|
|
|
])
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: undefined })).toEqual([])
|
|
|
|
|
|
|
|
// We should be able to use strings and Buffers interchangeably
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: Buffer.from('bar') })).toEqual([{ foo: Buffer.from('bar') }])
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: 'bar' })).toEqual([{ foo: Buffer.from('bar') }])
|
|
|
|
|
|
|
|
// We should be able to use strings and Buffers interchangeably in arrays
|
|
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders({ foo: [Buffer.from('bar'), 'baz'] })).toEqual([
|
|
|
|
{ foo: Buffer.from('bar') },
|
|
|
|
{ foo: Buffer.from('baz') },
|
|
|
|
])
|
|
|
|
})
|