Browse Source

Merge pull request #17 from Shopify/add_broker_addr_accessor

Add broker addr accessor
Evan Huus 11 years ago
parent
commit
4ed53bfd73
2 changed files with 10 additions and 1 deletions
  1. 5 0
      broker.go
  2. 5 1
      broker_test.go

+ 5 - 0
broker.go

@@ -102,6 +102,11 @@ func (b *Broker) ID() int32 {
 	return b.id
 }
 
+// Addr returns the broker address as either retrieved from Kafka's metadata or passed to NewBroker.
+func (b *Broker) Addr() string {
+	return b.addr
+}
+
 // Equals compares two brokers. Two brokers are considered equal if they have the same address and id,
 // or if they are both nil.
 func (b *Broker) Equals(a *Broker) bool {

+ 5 - 1
broker_test.go

@@ -197,7 +197,7 @@ func TestBrokerEquals(t *testing.T) {
 	}
 }
 
-func TestBrokerID(t *testing.T) {
+func TestBrokerAccessors(t *testing.T) {
 
 	broker := NewBroker("abc:123")
 
@@ -205,6 +205,10 @@ func TestBrokerID(t *testing.T) {
 		t.Error("New broker didn't have an ID of -1.")
 	}
 
+	if broker.Addr() != "abc:123" {
+		t.Error("New broker didn't have the correct address")
+	}
+
 	broker.id = 34
 	if broker.ID() != 34 {
 		t.Error("Manually setting broker ID did not take effect.")