|
|
@ -2,11 +2,11 @@ package hostess_test
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/cbednarski/hostess"
|
|
|
|
"github.com/cbednarski/hostess"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestHostname(t *testing.T) {
|
|
|
|
func TestHostname(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
h := hostess.Hostname{}
|
|
|
|
h := hostess.Hostname{}
|
|
|
|
h.Domain = domain
|
|
|
|
h.Domain = domain
|
|
|
|
h.Ip = ip
|
|
|
|
h.Ip = ip
|
|
|
@ -23,6 +23,48 @@ func TestHostname(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestEqual(t *testing.T) {
|
|
|
|
|
|
|
|
a := hostess.NewHostname("localhost", "127.0.0.1", true)
|
|
|
|
|
|
|
|
b := hostess.NewHostname("localhost", "127.0.0.1", false)
|
|
|
|
|
|
|
|
c := hostess.NewHostname("localhost", "127.0.1.1", false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !a.Equal(b) {
|
|
|
|
|
|
|
|
t.Errorf("%s and %s should be equal", a, b)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.Equal(c) {
|
|
|
|
|
|
|
|
t.Errorf("%s and %s should not be equal", a, c)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestEqualIp(t *testing.T) {
|
|
|
|
|
|
|
|
a := hostess.NewHostname("localhost", "127.0.0.1", true)
|
|
|
|
|
|
|
|
c := hostess.NewHostname("localhost", "127.0.1.1", false)
|
|
|
|
|
|
|
|
ip := net.ParseIP("127.0.0.1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !a.EqualIp(ip) {
|
|
|
|
|
|
|
|
t.Errorf("%s and %s should be equal", a.Ip, ip)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.EqualIp(c.Ip) {
|
|
|
|
|
|
|
|
t.Errorf("%s and %s should not be equal", a.Ip, c.Ip)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestIsValid(t *testing.T) {
|
|
|
|
|
|
|
|
a := hostess.NewHostname("localhost", "127.0.0.1", true)
|
|
|
|
|
|
|
|
d := hostess.NewHostname("", "127.0.0.1", true)
|
|
|
|
|
|
|
|
e := hostess.NewHostname("localhost", "localhost", true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !a.IsValid() {
|
|
|
|
|
|
|
|
t.Errorf("%s should be a valid hostname", a)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.IsValid() {
|
|
|
|
|
|
|
|
t.Errorf("%s should be invalid because the name is blank", d)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.IsValid() {
|
|
|
|
|
|
|
|
t.Errorf("%s should be invalid because the ip is malformed", e)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFormatHostname(t *testing.T) {
|
|
|
|
func TestFormatHostname(t *testing.T) {
|
|
|
|
hostname := &hostess.Hostname{domain, ip, enabled, false}
|
|
|
|
hostname := &hostess.Hostname{domain, ip, enabled, false}
|
|
|
|
|
|
|
|
|
|
|
|