client_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package websocket
  5. import (
  6. "net/url"
  7. "testing"
  8. )
  9. var hostPortNoPortTests = []struct {
  10. u *url.URL
  11. hostPort, hostNoPort string
  12. }{
  13. {&url.URL{Scheme: "ws", Host: "example.com"}, "example.com:80", "example.com"},
  14. {&url.URL{Scheme: "wss", Host: "example.com"}, "example.com:443", "example.com"},
  15. {&url.URL{Scheme: "ws", Host: "example.com:7777"}, "example.com:7777", "example.com"},
  16. {&url.URL{Scheme: "wss", Host: "example.com:7777"}, "example.com:7777", "example.com"},
  17. }
  18. func TestHostPortNoPort(t *testing.T) {
  19. for _, tt := range hostPortNoPortTests {
  20. hostPort, hostNoPort := hostPortNoPort(tt.u)
  21. if hostPort != tt.hostPort {
  22. t.Errorf("hostPortNoPort(%v) returned hostPort %q, want %q", tt.u, hostPort, tt.hostPort)
  23. }
  24. if hostNoPort != tt.hostNoPort {
  25. t.Errorf("hostPortNoPort(%v) returned hostNoPort %q, want %q", tt.u, hostNoPort, tt.hostNoPort)
  26. }
  27. }
  28. }