Skip to content

Instantly share code, notes, and snippets.

@schigh-ntwrk
Last active May 26, 2021 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schigh-ntwrk/e2ffedfaf689616bf536a2264542c6bd to your computer and use it in GitHub Desktop.
Save schigh-ntwrk/e2ffedfaf689616bf536a2264542c6bd to your computer and use it in GitHub Desktop.
use of naked braces in Go
t.Run("multi config default pool size", func(t *testing.T) {
_ = os.Setenv(EnvKafkaGlobalBrokers, "0.0.0.0:9092")
_ = os.Setenv(EnvKafkaSubscriberTopicGroups, "A:B|C:D")
cfgs, err := ConsumerConfigsFromEnv()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(cfgs) != 2 {
t.Fatalf("expected two config, got %d", len(cfgs))
}
{
// Topic A, Group B
cfg := cfgs[0]
if !reflect.DeepEqual(cfg.CommitInterval, time.Duration(0)) {
t.Fatalf("commit interval: expected %s, got %s", time.Duration(0), cfg.CommitInterval)
}
if !reflect.DeepEqual(cfg.PoolSize, defaultKafkaPoolSize) {
t.Fatalf("pool size: expected %d, got %d", defaultKafkaPoolSize, cfg.PoolSize)
}
if !reflect.DeepEqual(cfg.Topic, "A") {
t.Fatalf("topic: expected A, got %s", cfg.Topic)
}
if !reflect.DeepEqual(cfg.GroupID, "B") {
t.Fatalf("group id: expected B, got %s", cfg.GroupID)
}
if !reflect.DeepEqual(cfg.Brokers, []string{"0.0.0.0:9092"}) {
t.Fatalf("hosts: expected [0.0.0.0:9092], got %+v", cfg.Brokers)
}
}
{
// Topic C, Group D
cfg := cfgs[1]
if !reflect.DeepEqual(cfg.CommitInterval, time.Duration(0)) {
t.Fatalf("commit interval: expected %s, got %s", time.Duration(0), cfg.CommitInterval)
}
if !reflect.DeepEqual(cfg.PoolSize, defaultKafkaPoolSize) {
t.Fatalf("pool size: expected %d, got %d", defaultKafkaPoolSize, cfg.PoolSize)
}
if !reflect.DeepEqual(cfg.Topic, "C") {
t.Fatalf("topic: expected C, got %s", cfg.Topic)
}
if !reflect.DeepEqual(cfg.GroupID, "D") {
t.Fatalf("group id: expected D, got %s", cfg.GroupID)
}
if !reflect.DeepEqual(cfg.Brokers, []string{"0.0.0.0:9092"}) {
t.Fatalf("hosts: expected [0.0.0.0:9092], got %+v", cfg.Brokers)
}
}
reset()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment