connections_test.go 682 B

1234567891011121314151617181920212223242526
  1. // Copyright (C) 2016 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package connections
  7. import "testing"
  8. import "net/url"
  9. func TestFixupPort(t *testing.T) {
  10. cases := [][2]string{
  11. {"tcp://1.2.3.4:5", "tcp://1.2.3.4:5"},
  12. {"tcp://1.2.3.4:", "tcp://1.2.3.4:22000"},
  13. {"tcp://1.2.3.4", "tcp://1.2.3.4:22000"},
  14. }
  15. for _, tc := range cases {
  16. u0, _ := url.Parse(tc[0])
  17. u1 := fixupPort(u0).String()
  18. if u1 != tc[1] {
  19. t.Errorf("fixupPort(%q) => %q, expected %q", tc[0], u1, tc[1])
  20. }
  21. }
  22. }