From 1f8003b6acc970e253009ab1701ee638912b08cd Mon Sep 17 00:00:00 2001 From: Asim Date: Mon, 14 Mar 2016 20:09:07 +0000 Subject: [PATCH] extractor tests --- broker/extractor_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 broker/extractor_test.go diff --git a/broker/extractor_test.go b/broker/extractor_test.go new file mode 100644 index 00000000..382b9a7a --- /dev/null +++ b/broker/extractor_test.go @@ -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) + } + } + +}