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 5package websocket 6 7import ( 8 "net/url" 9 "testing" 10) 11 12var hostPortNoPortTests = []struct { 13 u *url.URL 14 hostPort, hostNoPort string 15}{ 16 {&url.URL{Scheme: "ws", Host: "example.com"}, "example.com:80", "example.com"}, 17 {&url.URL{Scheme: "wss", Host: "example.com"}, "example.com:443", "example.com"}, 18 {&url.URL{Scheme: "ws", Host: "example.com:7777"}, "example.com:7777", "example.com"}, 19 {&url.URL{Scheme: "wss", Host: "example.com:7777"}, "example.com:7777", "example.com"}, 20} 21 22func TestHostPortNoPort(t *testing.T) { 23 for _, tt := range hostPortNoPortTests { 24 hostPort, hostNoPort := hostPortNoPort(tt.u) 25 if hostPort != tt.hostPort { 26 t.Errorf("hostPortNoPort(%v) returned hostPort %q, want %q", tt.u, hostPort, tt.hostPort) 27 } 28 if hostNoPort != tt.hostNoPort { 29 t.Errorf("hostPortNoPort(%v) returned hostNoPort %q, want %q", tt.u, hostNoPort, tt.hostNoPort) 30 } 31 } 32} 33