@ -16,7 +16,10 @@ limitations under the License.
package urlutil
import "testing"
import (
"net/url"
"testing"
)
func TestURLJoin ( t * testing . T ) {
tests := [ ] struct {
@ -39,6 +42,33 @@ func TestURLJoin(t *testing.T) {
}
}
func TestSchemeHostAndPortMatches ( t * testing . T ) {
for _ , tt := range [ ] struct {
a , b string
match bool
} {
{ "http://example.com" , "http://example.com" , true } ,
{ "https://example.com" , "https://example.com" , true } ,
{ "http://example.com" , "https://example.com" , false } ,
{ "https://example.com" , "http://example.com" , false } ,
{ "http://example.com:80" , "http://example.com:80" , true } ,
{ "https://example.com:443" , "https://example.com:443" , true } ,
{ "http://example.com:1234" , "http://example.com:5678" , false } ,
{ "https://example.com:1234" , "https://example.com:5678" , false } ,
// The following lines are subject of change, currently only there
// to ensure that the existing logic works as expected and the
// upcoming fix / improvement works as wanted
{ "http://example.com:80" , "http://example.com" , false } ,
{ "https://example.com:443" , "https://example.com" , false } ,
} {
u1 , _ := url . Parse ( tt . a )
u2 , _ := url . Parse ( tt . b )
if tt . match != SchemeHostAndPortMatches ( u1 , u2 ) {
t . Errorf ( "Expected %q==%q to be %t" , tt . a , tt . b , tt . match )
}
}
}
func TestEqual ( t * testing . T ) {
for _ , tt := range [ ] struct {
a , b string