forked from mtusi2026/mtusi2026lab6
25 lines
665 B
Go
25 lines
665 B
Go
package config
|
|
|
|
import "testing"
|
|
|
|
// TestWorkerConfiguration requires a broker and gives each process an independent consumer ID.
|
|
func TestWorkerConfiguration(t *testing.T) {
|
|
t.Run("missing", func(t *testing.T) {
|
|
t.Setenv("BROKER_ADDRESS", "")
|
|
if _, err := NewWorker(); err == nil {
|
|
t.Fatal("missing broker accepted")
|
|
}
|
|
})
|
|
t.Run("configured", func(t *testing.T) {
|
|
t.Setenv("BROKER_ADDRESS", "broker:6379")
|
|
first, err := NewWorker()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := NewWorker()
|
|
if err != nil || first.Consumer == second.Consumer || first.BrokerAddress != "broker:6379" {
|
|
t.Fatal("invalid consumer configuration")
|
|
}
|
|
})
|
|
}
|