diff --git a/lib/connections/connections_test.go b/lib/connections/connections_test.go new file mode 100644 index 000000000..6fc50083a --- /dev/null +++ b/lib/connections/connections_test.go @@ -0,0 +1,26 @@ +// Copyright (C) 2016 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at http://mozilla.org/MPL/2.0/. + +package connections + +import "testing" +import "net/url" + +func TestFixupPort(t *testing.T) { + cases := [][2]string{ + {"tcp://1.2.3.4:5", "tcp://1.2.3.4:5"}, + {"tcp://1.2.3.4:", "tcp://1.2.3.4:22000"}, + {"tcp://1.2.3.4", "tcp://1.2.3.4:22000"}, + } + + for _, tc := range cases { + u0, _ := url.Parse(tc[0]) + u1 := fixupPort(u0).String() + if u1 != tc[1] { + t.Errorf("fixupPort(%q) => %q, expected %q", tc[0], u1, tc[1]) + } + } +} diff --git a/lib/connections/empty_test.go b/lib/connections/empty_test.go deleted file mode 100644 index 68e801e30..000000000 --- a/lib/connections/empty_test.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2016 The Syncthing Authors. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. - -// The existence of this file means we get 0% test coverage rather than no -// test coverage at all. Remove when implementing an actual test. - -package connections diff --git a/lib/connections/tcp_listen.go b/lib/connections/tcp_listen.go index e0011a068..9ae58faed 100644 --- a/lib/connections/tcp_listen.go +++ b/lib/connections/tcp_listen.go @@ -192,7 +192,7 @@ func fixupPort(uri *url.URL) *url.URL { copyURI := *uri host, port, err := net.SplitHostPort(uri.Host) - if err != nil && strings.HasPrefix(err.Error(), "missing port") { + if err != nil && strings.Contains(err.Error(), "missing port") { // addr is on the form "1.2.3.4" copyURI.Host = net.JoinHostPort(uri.Host, "22000") } else if err == nil && port == "" {