mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-25 11:17:50 +01:00
28 lines
1.4 KiB
TypeScript
28 lines
1.4 KiB
TypeScript
import { convertKafkaJSHeadersToRdKafkaHeaders } from '../../src/utils/db/kafka-producer-wrapper'
|
|
|
|
test('can convert from KafkaJS headers to rdkafka headers', () => {
|
|
expect(convertKafkaJSHeadersToRdKafkaHeaders()).toEqual(undefined)
|
|
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') },
|
|
])
|
|
})
|