diff --git a/irc.go b/irc.go index 7fb086c..5948ee8 100644 --- a/irc.go +++ b/irc.go @@ -389,9 +389,9 @@ func IRC(nick, user string) *Connection { return irc } -// Returns true if all values in struct make -// somewhat sense. -func (irc *Connection) hasValidValues() bool { +// Returns true if all values in struct allow for +// establishing a connection. +func (irc *Connection) hasConnectionValues() bool { if 0 == len(irc.nick) { return false } @@ -404,6 +404,10 @@ func (irc *Connection) hasValidValues() bool { return false } + if 0 == len(irc.server) { + return false + } + if nil == irc.Log { return false } diff --git a/irc_test.go b/irc_test.go index 8a71e2b..a829c3c 100644 --- a/irc_test.go +++ b/irc_test.go @@ -163,25 +163,27 @@ func TestIRCemptyUser(t *testing.T) { } -func TestHasValidValues0(t *testing.T) { +func TestHasConnectionValues0(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } - if false == irccon.hasValidValues() { + irccon.server = "foo" + if false == irccon.hasConnectionValues() { t.Error("valid struct not detected as such") } } -func TestHasValidValues1(t *testing.T) { +func TestHasConnectionValues1(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.Version = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'Version' not detected") } } @@ -191,33 +193,47 @@ func TestHasValidValues2(t *testing.T) { if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.nick = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'nick' not detected") } } -func TestHasValidValues3(t *testing.T) { +func TestHasConnectionValues3(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } + irccon.server = "foo" irccon.user = "" - if irccon.hasValidValues() { + if irccon.hasConnectionValues() { t.Error("empty 'user' not detected") } } -func TestHasValidValues4(t *testing.T) { +func TestHasConnectionValues4(t *testing.T) { + irccon := IRC("go-eventirc", "go-eventirc") + if nil == irccon { + t.Error("creating IRC struct failed") + } + irccon.server = "foo" + + irccon.Log = nil + if irccon.hasConnectionValues() { + t.Error("nil pointer 'Log' not detected") + } +} + +func TestHasConnectionValues5(t *testing.T) { irccon := IRC("go-eventirc", "go-eventirc") if nil == irccon { t.Error("creating IRC struct failed") } - irccon.Log = nil - if irccon.hasValidValues() { - t.Error("nil pointer 'Log' not detected") + if irccon.hasConnectionValues() { + t.Error("empty 'server' not detected") } }