Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
fix: pass always Kafka proxy extra args config to the constructor (#29)
Browse files Browse the repository at this point in the history
* fix: pass always Kafka proxy extra args config to the constructor

* remove extra line
  • Loading branch information
smoya authored Aug 27, 2021
1 parent 117af93 commit 828e143
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions config/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *KafkaProxy) ProxyConfig(doc []byte, debug bool, messageHandlers ...kafk
var kafkaProxyConfig *kafka.ProxyConfig
var err error
if len(doc) > 0 {
kafkaProxyConfig, err = c.configFromDoc(doc)
kafkaProxyConfig, err = c.configFromDoc(doc, kafka.WithExtra(c.ExtraFlags.Values))
} else {
kafkaProxyConfig, err = kafka.NewProxyConfig(c.BrokersMapping.Values, kafka.WithDialAddressMapping(c.BrokersDialMapping.Values), kafka.WithExtra(c.ExtraFlags.Values))
}
Expand All @@ -70,13 +70,12 @@ func (c *KafkaProxy) ProxyConfig(doc []byte, debug bool, messageHandlers ...kafk
return kafkaProxyConfig, nil
}

func (c *KafkaProxy) configFromDoc(d []byte) (*kafka.ProxyConfig, error) {
func (c *KafkaProxy) configFromDoc(d []byte, opts ...kafka.Option) (*kafka.ProxyConfig, error) {
doc := new(v2.Document)
if err := v2.Decode(d, doc); err != nil {
return nil, errors.Wrap(err, "error decoding AsyncAPI json doc to Document struct")
}

var opts []kafka.Option
if c.MessageValidation.Enabled {
validator, err := v2.FromDocJSONSchemaMessageValidator(doc)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions config/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ func TestKafkaProxy_ProxyConfig(t *testing.T) {
name: "Valid config. Only one broker from doc",
config: &KafkaProxy{
BrokerFromServer: "test",
// Also testing extra flags.
ExtraFlags: pipeSeparatedValues{Values: []string{"arg1=arg1value", "arg2=arg2value"}},
},
expectedProxyConfig: func(_ *testing.T, _ *kafka.ProxyConfig) *kafka.ProxyConfig {
return &kafka.ProxyConfig{
BrokersMapping: []string{"broker.mybrokers.org:9092,:9092"},
ExtraConfig: []string{"arg1=arg1value", "arg2=arg2value"},
}
},
doc: []byte(`testdata/simple-kafka.yaml`),
Expand Down

0 comments on commit 828e143

Please sign in to comment.