@@ -16,6 +16,7 @@ package kafkaexporter
1616
1717import (
1818 "context"
19+ "github.com/Shopify/sarama"
1920 "testing"
2021
2122 "github.com/stretchr/testify/assert"
@@ -41,7 +42,7 @@ func TestCreateTracesExporter(t *testing.T) {
4142 cfg .ProtocolVersion = "2.0.0"
4243 // this disables contacting the broker so we can successfully create the exporter
4344 cfg .Metadata .Full = false
44- f := kafkaExporterFactory {tracesMarshalers : tracesMarshalers ()}
45+ f := kafkaExporterFactory {tracesMarshalers : tracesMarshalers (), converters : getConverters () }
4546 r , err := f .createTracesExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
4647 require .NoError (t , err )
4748 assert .NotNil (t , r )
@@ -53,7 +54,7 @@ func TestCreateMetricsExport(t *testing.T) {
5354 cfg .ProtocolVersion = "2.0.0"
5455 // this disables contacting the broker so we can successfully create the exporter
5556 cfg .Metadata .Full = false
56- mf := kafkaExporterFactory {metricsMarshalers : metricsMarshalers ()}
57+ mf := kafkaExporterFactory {metricsMarshalers : metricsMarshalers (), converters : getConverters () }
5758 mr , err := mf .createMetricsExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
5859 require .NoError (t , err )
5960 assert .NotNil (t , mr )
@@ -65,7 +66,7 @@ func TestCreateLogsExport(t *testing.T) {
6566 cfg .ProtocolVersion = "2.0.0"
6667 // this disables contacting the broker so we can successfully create the exporter
6768 cfg .Metadata .Full = false
68- mf := kafkaExporterFactory {logsMarshalers : logsMarshalers ()}
69+ mf := kafkaExporterFactory {logsMarshalers : logsMarshalers (), converters : getConverters () }
6970 mr , err := mf .createLogsExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
7071 require .NoError (t , err )
7172 assert .NotNil (t , mr )
@@ -75,7 +76,7 @@ func TestCreateTracesExporter_err(t *testing.T) {
7576 cfg := createDefaultConfig ().(* Config )
7677 cfg .Brokers = []string {"invalid:9092" }
7778 cfg .ProtocolVersion = "2.0.0"
78- f := kafkaExporterFactory {tracesMarshalers : tracesMarshalers ()}
79+ f := kafkaExporterFactory {tracesMarshalers : tracesMarshalers (), converters : getConverters () }
7980 r , err := f .createTracesExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
8081 // no available broker
8182 require .Error (t , err )
@@ -86,7 +87,7 @@ func TestCreateMetricsExporter_err(t *testing.T) {
8687 cfg := createDefaultConfig ().(* Config )
8788 cfg .Brokers = []string {"invalid:9092" }
8889 cfg .ProtocolVersion = "2.0.0"
89- mf := kafkaExporterFactory {metricsMarshalers : metricsMarshalers ()}
90+ mf := kafkaExporterFactory {metricsMarshalers : metricsMarshalers (), converters : getConverters () }
9091 mr , err := mf .createMetricsExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
9192 require .Error (t , err )
9293 assert .Nil (t , mr )
@@ -96,15 +97,16 @@ func TestCreateLogsExporter_err(t *testing.T) {
9697 cfg := createDefaultConfig ().(* Config )
9798 cfg .Brokers = []string {"invalid:9092" }
9899 cfg .ProtocolVersion = "2.0.0"
99- mf := kafkaExporterFactory {logsMarshalers : logsMarshalers ()}
100+ mf := kafkaExporterFactory {logsMarshalers : logsMarshalers (), converters : getConverters () }
100101 mr , err := mf .createLogsExporter (context .Background (), component.ExporterCreateParams {Logger : zap .NewNop ()}, cfg )
101102 require .Error (t , err )
102103 assert .Nil (t , mr )
103104}
104105
105106func TestWithMarshalers (t * testing.T ) {
106107 cm := & customMarshaler {}
107- f := NewFactory (WithTracesMarshalers (cm ))
108+ cc := & customConverter {}
109+ f := NewFactory (WithTracesMarshalers (cm ), WithConverters (cc ))
108110 cfg := createDefaultConfig ().(* Config )
109111 // disable contacting broker
110112 cfg .Metadata .Full = false
@@ -135,3 +137,15 @@ func (c customMarshaler) Marshal(_ pdata.Traces) ([]Message, error) {
135137func (c customMarshaler ) Encoding () string {
136138 return "custom"
137139}
140+
141+ type customConverter struct {
142+ }
143+
144+ func (c customConverter ) ConvertMessages (messages []Message , topic string ) []* sarama.ProducerMessage {
145+ panic ("implement me" )
146+ }
147+
148+ func (c customConverter ) Encoding () string {
149+ return "custom"
150+ }
151+ var _ MessageConverter = (* customConverter )(nil )
0 commit comments