Merge pull request #59 from micro/tests

Tests round 2
This commit is contained in:
Asim 2016-03-14 21:56:38 +00:00
commit c48f711aab

38
broker/extractor_test.go Normal file
View File

@ -0,0 +1,38 @@
package broker
import (
"net"
"testing"
)
func TestExtractor(t *testing.T) {
testData := []struct {
addr string
expect string
parse bool
}{
{"127.0.0.1", "127.0.0.1", false},
{"10.0.0.1", "10.0.0.1", false},
{"", "", true},
{"0.0.0.0", "", true},
{"[::]", "", true},
}
for _, d := range testData {
addr, err := extractAddress(d.addr)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
if d.parse {
ip := net.ParseIP(addr)
if ip == nil {
t.Error("Unexpected nil IP")
}
} else if addr != d.expect {
t.Errorf("Expected %s got %s", d.expect, addr)
}
}
}