From 1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 13 Nov 2017 09:09:58 -0800 Subject: Updating server dependancies. (#7816) --- .../github.com/hashicorp/memberlist/util_test.go | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'vendor/github.com/hashicorp/memberlist/util_test.go') diff --git a/vendor/github.com/hashicorp/memberlist/util_test.go b/vendor/github.com/hashicorp/memberlist/util_test.go index e1d8eba01..b7f2b4199 100644 --- a/vendor/github.com/hashicorp/memberlist/util_test.go +++ b/vendor/github.com/hashicorp/memberlist/util_test.go @@ -7,24 +7,31 @@ import ( "time" ) -func Test_hasPort(t *testing.T) { - cases := []struct { - s string - expected bool +func TestUtil_PortFunctions(t *testing.T) { + tests := []struct { + addr string + hasPort bool + ensurePort string }{ - {"", false}, - {":80", true}, - {"127.0.0.1", false}, - {"127.0.0.1:80", true}, - {"::1", false}, - {"2001:db8:a0b:12f0::1", false}, - {"[2001:db8:a0b:12f0::1]", false}, - {"[2001:db8:a0b:12f0::1]:80", true}, - } - for _, c := range cases { - if hasPort(c.s) != c.expected { - t.Fatalf("bad: '%s' hasPort was not %v", c.s, c.expected) - } + {"1.2.3.4", false, "1.2.3.4:8301"}, + {"1.2.3.4:1234", true, "1.2.3.4:1234"}, + {"2600:1f14:e22:1501:f9a:2e0c:a167:67e8", false, "[2600:1f14:e22:1501:f9a:2e0c:a167:67e8]:8301"}, + {"[2600:1f14:e22:1501:f9a:2e0c:a167:67e8]", false, "[2600:1f14:e22:1501:f9a:2e0c:a167:67e8]:8301"}, + {"[2600:1f14:e22:1501:f9a:2e0c:a167:67e8]:1234", true, "[2600:1f14:e22:1501:f9a:2e0c:a167:67e8]:1234"}, + {"localhost", false, "localhost:8301"}, + {"localhost:1234", true, "localhost:1234"}, + {"hashicorp.com", false, "hashicorp.com:8301"}, + {"hashicorp.com:1234", true, "hashicorp.com:1234"}, + } + for _, tt := range tests { + t.Run(tt.addr, func(t *testing.T) { + if got, want := hasPort(tt.addr), tt.hasPort; got != want { + t.Fatalf("got %v want %v", got, want) + } + if got, want := ensurePort(tt.addr, 8301), tt.ensurePort; got != want { + t.Fatalf("got %v want %v", got, want) + } + }) } } -- cgit v1.2.3-1-g7c22