0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-29 03:04:16 +01:00
posthog/plugin-server/tests/utils/kafka-producer-wrapper.test.ts
Harry Waye 616389713b
revert: use rdkafka consumer for analytics ingestion and onEvent (#15469)
Revert "chore: use rdkafka consumer for analytics ingestion and onEvent (#15432)"

This reverts commit 85bb582cee.
2023-05-10 12:22:38 +00:00

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([])
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') },
])
})