-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
defaults -topic & -brokers to env vars KT_TOPIC & KT_BROKERS (fix #14).
- Loading branch information
Showing
6 changed files
with
282 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestProduceParseArgs(t *testing.T) { | ||
configBefore := config | ||
defer func() { | ||
config = configBefore | ||
}() | ||
|
||
expectedTopic := "test-topic" | ||
givenBroker := "hans:9092" | ||
expectedBrokers := []string{givenBroker} | ||
|
||
config.produce.args.topic = "" | ||
config.produce.args.brokers = "" | ||
os.Setenv("KT_TOPIC", expectedTopic) | ||
os.Setenv("KT_BROKERS", givenBroker) | ||
|
||
produceParseArgs() | ||
if config.produce.topic != expectedTopic || | ||
!reflect.DeepEqual(config.produce.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected topic %v and brokers %v from env vars, got topic %v and brokers %v.", | ||
expectedTopic, | ||
expectedBrokers, | ||
config.produce.topic, | ||
config.produce.brokers, | ||
) | ||
return | ||
} | ||
|
||
// default brokers to localhost:9092 | ||
os.Setenv("KT_TOPIC", "") | ||
os.Setenv("KT_BROKERS", "") | ||
config.produce.args.topic = expectedTopic | ||
config.produce.args.brokers = "" | ||
expectedBrokers = []string{"localhost:9092"} | ||
|
||
produceParseArgs() | ||
if config.produce.topic != expectedTopic || | ||
!reflect.DeepEqual(config.produce.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected topic %v and brokers %v from env vars, got topic %v and brokers %v.", | ||
expectedTopic, | ||
expectedBrokers, | ||
config.produce.topic, | ||
config.produce.brokers, | ||
) | ||
return | ||
} | ||
|
||
// command line arg wins | ||
os.Setenv("KT_TOPIC", "BLUBB") | ||
os.Setenv("KT_BROKERS", "BLABB") | ||
config.produce.args.topic = expectedTopic | ||
config.produce.args.brokers = givenBroker | ||
expectedBrokers = []string{givenBroker} | ||
|
||
produceParseArgs() | ||
if config.produce.topic != expectedTopic || | ||
!reflect.DeepEqual(config.produce.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected topic %v and brokers %v from env vars, got topic %v and brokers %v.", | ||
expectedTopic, | ||
expectedBrokers, | ||
config.produce.topic, | ||
config.produce.brokers, | ||
) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestTopicParseArgs(t *testing.T) { | ||
configBefore := config | ||
defer func() { | ||
config = configBefore | ||
}() | ||
|
||
givenBroker := "hans:9092" | ||
expectedBrokers := []string{givenBroker} | ||
|
||
config.topic.args.brokers = "" | ||
os.Setenv("KT_BROKERS", givenBroker) | ||
|
||
topicParseArgs() | ||
if !reflect.DeepEqual(config.topic.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected brokers %v from env vars, got brokers %v.", | ||
expectedBrokers, | ||
config.topic.brokers, | ||
) | ||
return | ||
} | ||
|
||
// default brokers to localhost:9092 | ||
os.Setenv("KT_BROKERS", "") | ||
config.topic.args.brokers = "" | ||
expectedBrokers = []string{"localhost:9092"} | ||
|
||
topicParseArgs() | ||
if !reflect.DeepEqual(config.topic.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected brokers %v from env vars, got brokers %v.", | ||
expectedBrokers, | ||
config.topic.brokers, | ||
) | ||
return | ||
} | ||
|
||
// command line arg wins | ||
os.Setenv("KT_BROKERS", "BLABB") | ||
config.topic.args.brokers = givenBroker | ||
expectedBrokers = []string{givenBroker} | ||
|
||
topicParseArgs() | ||
if !reflect.DeepEqual(config.topic.brokers, expectedBrokers) { | ||
t.Errorf( | ||
"Expected brokers %v from env vars, got brokers %v.", | ||
expectedBrokers, | ||
config.topic.brokers, | ||
) | ||
return | ||
} | ||
} |