diff --git a/pkg/config/config.go b/pkg/config/config.go index e8dca64..7fe4d83 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -137,6 +137,9 @@ func parseTLSConfig(config *fTLSConfig, defaultServerName string, basePath strin } func parseMQTTSink(basePath string, sinkID int, sink *fMQTTSink) (*MQTTSink, error) { + if sink == nil { + sink = &fMQTTSink{} + } res := &MQTTSink{} if sink.Name == "" { res.Name = fmt.Sprintf("unnamed-mqtt-sink-%d", sinkID) @@ -196,6 +199,9 @@ func parseMQTTSink(basePath string, sinkID int, sink *fMQTTSink) (*MQTTSink, err } func parseCloudPubSubSink(basePath string, sinkID int, sink *fCloudPubSubSink) (*CloudPubSubSink, error) { + if sink == nil { + sink = &fCloudPubSubSink{} + } ctx := context.Background() res := &CloudPubSubSink{} if sink.Name == "" { @@ -246,6 +252,9 @@ func parseCloudPubSubSink(basePath string, sinkID int, sink *fCloudPubSubSink) ( } func parseStdoutSink(sinkID int, sink *fStdoutSink) (*StdoutSink, error) { + if sink == nil { + sink = &fStdoutSink{} + } res := &StdoutSink{} if sink.Name == "" { res.Name = fmt.Sprintf("unnamed-stdout-sink-%d", sinkID) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index aa627c4..4aba392 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -134,3 +134,21 @@ func TestParsingEmpty(t *testing.T) { t.Errorf("unexpected difference:\n%v", diff) } } + +func TestParsingEmptySink(t *testing.T) { + config, err := Read("testdata/test2/config.toml") + if err != nil { + t.Fatalf("Failed to parse config: %v", err) + } + expectedConfig := &Config{ + Adapter: "hci0", + Sinks: []Sink{ + &StdoutSink{ + Name: "unnamed-stdout-sink-0", + }, + }, + } + if diff := cmpConfig(config, expectedConfig); diff != "" { + t.Errorf("unexpected difference:\n%v", diff) + } +} diff --git a/pkg/config/testdata/test2/config.toml b/pkg/config/testdata/test2/config.toml new file mode 100644 index 0000000..5d4f713 --- /dev/null +++ b/pkg/config/testdata/test2/config.toml @@ -0,0 +1 @@ +[[sinks.stdout]]