mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
lib/connections: Fix port fixup in Go 1.8 (fixes #3817)
The test for the error string is fragile, and the error string changed in Go 1.8 so the relevant part is no longer a prefix. This covers it with a test though, so it should be fine in the future as well. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3818
This commit is contained in:
parent
f67c5a2fd6
commit
9c67bd2550
26
lib/connections/connections_test.go
Normal file
26
lib/connections/connections_test.go
Normal file
@ -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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
@ -192,7 +192,7 @@ func fixupPort(uri *url.URL) *url.URL {
|
|||||||
copyURI := *uri
|
copyURI := *uri
|
||||||
|
|
||||||
host, port, err := net.SplitHostPort(uri.Host)
|
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"
|
// addr is on the form "1.2.3.4"
|
||||||
copyURI.Host = net.JoinHostPort(uri.Host, "22000")
|
copyURI.Host = net.JoinHostPort(uri.Host, "22000")
|
||||||
} else if err == nil && port == "" {
|
} else if err == nil && port == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user