2016-06-15 13:50:56 +02:00
|
|
|
// Copyright (c) 2012-2014 Jeremy Latt
|
2017-03-27 14:15:02 +02:00
|
|
|
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
|
2016-06-15 13:50:56 +02:00
|
|
|
// released under the MIT license
|
|
|
|
|
2017-10-05 15:47:43 +02:00
|
|
|
package utils
|
2016-04-21 14:32:17 +02:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
// hostnames from https://github.com/DanielOaks/irc-parser-tests
|
|
|
|
var (
|
|
|
|
goodHostnames = []string{
|
|
|
|
"irc.example.com",
|
|
|
|
"i.coolguy.net",
|
|
|
|
"irc-srv.net.uk",
|
|
|
|
"iRC.CooLguY.NeT",
|
|
|
|
"gsf.ds342.co.uk",
|
|
|
|
"324.net.uk",
|
|
|
|
"xn--bcher-kva.ch",
|
|
|
|
}
|
|
|
|
|
|
|
|
badHostnames = []string{
|
|
|
|
"-lol-.net.uk",
|
|
|
|
"-lol.net.uk",
|
|
|
|
"_irc._sctp.lol.net.uk",
|
|
|
|
"irc",
|
|
|
|
"com",
|
|
|
|
"",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsHostname(t *testing.T) {
|
|
|
|
for _, name := range goodHostnames {
|
|
|
|
if !IsHostname(name) {
|
|
|
|
t.Error(
|
|
|
|
"Expected to pass, but could not validate hostname",
|
|
|
|
name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range badHostnames {
|
|
|
|
if IsHostname(name) {
|
|
|
|
t.Error(
|
|
|
|
"Expected to fail, but successfully validated hostname",
|
|
|
|
name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|